Skip to content

Determinism and compatibility of random module #1269

@HyeonuPark

Description

@HyeonuPark

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?

Python document states this in https://docs.python.org/3/library/random.html#notes-on-reproducibility

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions