Question

I'm a newbie on python and flask. When reading flask tutorial on the official web site, I found that the using urandom() function is recommended way of generating secret key.

In here, I'm wondering how the random number is generated by urandom(), and why this is more cryptographically safe.

I know the basic principle used in random generator used in C, and if the same principle is used in the urandom, it should be initialized with random seed. However, I don't see the seed related function in os module API.

I found some articles saying that it refers some value on specific locations but I don't know how it can be related to randomness and why it is safe to use.

Was it helpful?

Solution

This function returns random bytes from an OS-specific randomness source. The returned data should be unpredictable enough for cryptographic applications, though its exact quality depends on the OS implementation. On a UNIX-like system this will query /dev/urandom, and on Windows it will use CryptGenRandom(). If a randomness source is not found, NotImplementedError will be raised.

For an easy-to-use interface to the random number generator provided by your platform, please see random.SystemRandom.

[Source]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top