I'm searching for a program that can generate random but valid python programs, similar to the
Random C program generator.
I was trying to do this myself giving random input to the python tokenize.untokenize()
function, but of course most of the generated source code was not a valid program I could interpret with eval()
. So I would like to know, if you either know a way how to generate random but valid python programs (maybe using the ast
module?) or if such a generator already exists.
EDIT: I want to use the random python source code as a starting point for doing genetic programming with python. So I want to have a list of random programs, and then evolve them towards let's say a program that returns "Hello World!".