Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching for a random python program generator

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!".

like image 277
asmaier Avatar asked Feb 26 '11 17:02

asmaier


People also ask

Does Python have a random number generator?

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.

What is random generator in Python?

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.


1 Answers

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.

like image 89
J. Taylor Avatar answered Sep 30 '22 18:09

J. Taylor