Can I generate authentic random number with python?

The documentation for the random module has this to say:

Warning: The pseudo-random generators of this module should not be used for security purposes. Use os.urandom() or SystemRandom if you require a cryptographically secure pseudo-random number generator.


Truly random numbers can be generated from

https://pypi.python.org/pypi/quantumrandom/

pip install quantumrandom

Currently you are limited to blocks of 1024 but with a bit of simple programming and a little bit of time you will be able to extend this limit to a large enough sample for most applications.


Python has nothing that allows you to generate "truly random" or "authentic random" numbers, in the sense that they are uniformly distributed and independent of everything else (especially the latter).

In any case, the distinction between "pseudorandom" and "truly random" numbers is not what applications care about. Rather, the requirements for randomness depend on the application, and you didn't really specify what kind of application you have in mind. For example, in general:

  • Security applications care whether the numbers are hard to guess; in this case, only a cryptographic RNG can achieve this requirement (even one that relies on a pseudorandom number generator). A Python example is the secrets module or random.SystemRandom.
  • Scientific simulations care whether the numbers behave like independent uniform random numbers, and often care whether the numbers are reproducible at a later time. A Python example is numpy.random.Generator or random.Random.

See also these questions:

  • Checking noise in binary sequence for randomness
  • How to get truly random data, not random data fed into a PRNG seed like CSRNG's do?