generate random numbers in a deterministic way

Jabba Laci jabba.laci at gmail.com
Wed Apr 25 01:51:18 EDT 2012


Hi,

I'm working with some sorting algorithms and I want to compare their
efficiency. One test fills a list with one million random integers,
which serves as input for the algorithms. However, if this list is
different each time I run the tests, the tests wouldn't be fair. At
the moment the selected sorting alg. can be specified with a switch
and only one alg. is tested each time.

So what I want is the following: fill the list with random numbers,
but when I re-execute the script, I want the same "random" numbers in
the same order. This way each sorting alg. would get the same input.

As a workaround, I made a generator that outputs a random list in a
file, and this list is read each time by the testing script. I just
wonder if there is a more elegant solution.

Thanks,

Laszlo



More information about the Python-list mailing list