You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Should random.random() always be same when same random.seed() is applied? Should this be same across interpreter process? Should this be same across RustPython version? Should this be same with how CPython does?
Sometimes it is useful to be able to reproduce the sequences given by a pseudo random number generator. By re-using a seed value, the same sequence should be reproducible from run to run as long as multiple threads are not running.
Most of the random module’s algorithms and seeding functions are subject to change across Python versions, but two aspects are guaranteed not to change:
If a new seeding method is added, then a backward compatible seeder will be offered.
The generator’s random() method will continue to produce the same sequence when the compatible seeder is given the same seed.
random.seed() takes version argument which can be 1 or 2.
With version 2 (the default), a str, bytes, or bytearray object gets converted to an int and all of its bits are used.
With version 1 (provided for reproducing random sequences from older versions of Python), the algorithm for str and bytes generates a narrower range of seeds.
The text was updated successfully, but these errors were encountered:
In CPython, random.seed version handling and stuffs are implemented in Python in random.py, which uses _random C module. Current RustPython implementation is reimplementing random, not _random, so can't share Python part.
#1571 is an effort to fix it which should help this issue.
I think it is best to use a modern RNG by default (i.e. rand::rngs::StdRng), possibly falling back to the Mersenne Twister when reproducibility is required (i.e. when seed is called).
Should
random.random()
always be same when samerandom.seed()
is applied? Should this be same across interpreter process? Should this be same across RustPython version? Should this be same with how CPython does?Python document states this in https://docs.python.org/3/library/random.html#notes-on-reproducibility
random.seed()
takesversion
argument which can be 1 or 2.The text was updated successfully, but these errors were encountered: