0

I want to know how the random.py module does to generate a random number? I read the random.py file but I did not understand the comments. does it use a mathematical property? Is it possible to create own random.py?

IIX 61
  • 17
  • 7

1 Answers1

2

From the documentation for random.py:

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.

(emphasis and hyperlinking mine)

Christian Dean
  • 22,138
  • 7
  • 54
  • 87