D
D
DVoropaev2019-05-30 06:35:48
Python
DVoropaev, 2019-05-30 06:35:48

Why doesn't python random number generator pass NIST tests?

#!/usr/bin/env python3
import random


while True:
        s = ""
        for i in range(0, 500):
                s = s + str(random.randint(0, 1))
        print(s)
        input()

5cef4f6edd24d742449545.png
Does this mean that it cannot be used in cryptography?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
aRegius, 2019-05-30
@aRegius

The random module computes random numbers using the Mersenne Twister algorithm ... Functions in random() should not be used in programs related to cryptography. If you need such functionality, consider using functions in the ssl module instead. For example, ssl.RAND_bytes() can be used to generate a cryptographically secure sequence of random bytes.

David Beazley

A
Alexander Varakosov, 2019-05-30
@thelongrunsmoke

The built-in random never passes NIST tests. For the needs of cryptography, other sources of entropy are needed, for example, the secrets module .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question