Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Python generate random numbers?

Tags:

python

random

I understand that I should use os.urandom() or SystemRandom in Python for 'secure' pseudo-random numbers.

But how does Python generate these random numbers logically?

Also is there a way to generate a number in Python that is 'more random' than others?

like image 627
ruben_KAI Avatar asked Oct 07 '14 15:10

ruben_KAI


1 Answers

For "secure" random numbers, Python doesn't actually generate them: it gets them from the operating system, which has a special driver that gathers entropy from various real-world sources, such as variations in timing between keystrokes and disk seeks.

like image 51
Wyzard Avatar answered Sep 30 '22 10:09

Wyzard