Random number in the range 1 to sys.maxsize is always 1 mod 2^10

后端 未结 3 1267
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 08:55

I am trying to find the statistical properties of the PRNGs available in Python (2.7.10) by using the frequency test, runs test and the chi squared test.

For carryin

3条回答
  •  无人及你
    2021-01-01 09:11

    That depends on a lot of things, like how exactly the RNG is implemented, how much bits of state it uses, and how exactly the sample function is implemented.

    Here's what the documentation says:

    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. It produces 53-bit precision floats and has a period of 2**19937-1.

    So if the sample indeed uses random() under the hood, then you should only expect 53 bits of meaningful bits in your result.

提交回复
热议问题