Reproducibility of python pseudo-random numbers across systems and versions?

后端 未结 5 707
后悔当初
后悔当初 2020-12-20 12:08

I need to generate a controlled sequence of pseudo-random numbers, given an initial parameter. For that I\'m using the standard python random generator, seeded by this param

5条回答
  •  天命终不由人
    2020-12-20 12:37

    No, it doesn't. There's no such promise in the random module's documentation.

    What the docs do contain is this remark:

    Changed in version 2.3: MersenneTwister replaced Wichmann-Hill as the default generator

    So a different RNG was used prior to Python 2.3.

    So far, I've been using numpy.random.RandomState for reproducible pseudo-randomness, though it too does not make the formal promise you're after.

    If you want full reproducibility, you might want to include a copy of random's source in your program, or hack together a "P²RNG" (pseudo-pseudo-RNG) from hashlib.

提交回复
热议问题