I came across this method in Pycrypto, which is used to generate random bytes:
from Crypto import Random
Random.get_random_bytes(5)
I was wondering how this method is different from a simple generator like the following:
import random
def get_random_bytes(N):
ASCII = "".join(chr(x) for x in range(255))
return "".join(random.choice(ASCII) for _ in range(n))
Note: my intuition is that the Pycrypto method is more cryptographically "sound". Looking at random
's documentation, it says that it is based on a generator with a period of 2**19937-1
. Looking at Random.get_random_bytes
, it states that it is capable of generating cryptographically-strong bytes. What does that mean?
Of course, I wish to use the library implementation, instead of my own. I just want to understand the cryptography concepts behind it.