Is python's random number generation easily reproducible?

前端 未结 4 1694
轮回少年
轮回少年 2021-01-13 12:01

I was reading about python\'s random module in standard library. It amazes me that when I set the seed and produce a few random numbers:

random.seed(1)
for i         


        
4条回答
  •  我在风中等你
    2021-01-13 12:25

    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. The underlying implementation in C is both fast and threadsafe. The Mersenne Twister is one of the most extensively tested random number generators in existence. However, being completely deterministic, it is not suitable for all purposes, and is completely unsuitable for cryptographic purposes.

    See this answer for secure random.

提交回复
热议问题