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!".
Almost all module functions depend on the basic function random() , which generates a random float uniformly in the semi-open range [0.0, 1.0). Python uses the Mersenne Twister as the core generator.
Python defines a set of functions that are used to generate or manipulate random numbers through the random module. Functions in the random module rely on a pseudo-random number generator function random(), which generates a random float number between 0.0 and 1.0.
A google search for python "random program generator" turned up the Random Python Program Generator.
If you want a downloadable script, take a look at pyfuzz.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With