I\'m working on a project with a friend where we need to generate a random hash. Before we had time to discuss, we both came up with different approaches and because they are us
random.random()
is a pseudo-radmom generator, that means the numbers are generated from a sequence. if you call random.seed(some_number)
, then after that the generated sequence will always be the same.
os.urandom()
get's the random numbers from the os' rng, which uses an entropy pool to collect real random numbers, usually by random events from hardware devices, there exist even random special entropy generators for systems where a lot of random numbers are generated.
on unix system there are traditionally two random number generators: /dev/random
and /dev/urandom
. calls to the first block if there is not enough entropy available, whereas when you read /dev/urandom
and there is not enough entropy data available, it uses a pseudo-rng and doesn't block.
so the use depends usually on what you need: if you need a few, equally distributed random numbers, then the built in prng should be sufficient. for cryptographic use it's always better to use real random numbers.