Python's random library... interesting info

Published:

Updated:

Python's standard random library uses the Mersenne Twister algorithm to generate random numbers. This can also be found in the add on NumPy library as the MT19937 bit generator. It generates 53 bit precision floats over a very long period of 2^19937-1. It is, however NOT cryptographically secure.

If you are interested in the seed that generated your numbers, you can always supply your own with random.seed(46) for example, but if the seed does not change, the sequence stays the same.

Instead it will rely on it's own seed generation which you can view by querying the state...

state = random.getstate()

print(state)

Will return a tuple of information. Saving this will allow you to start up again with the same state by using 

continuedState = random.setstate(state)

Therefore I believe my QP generator to be "random enough".

Not sure what this info is good for other than Pyrhon trivia, but I also fall in the rabbit holes on occasion...

Entry #472

Comments

This Blog entry currently has no comments.

Post a Comment

Please Log In

To use this feature you must be logged into your Lottery Post account.

Not a member yet?

If you don't yet have a Lottery Post account, it's simple and free to create one! Just tap the Register button and after a quick process you'll be part of our lottery community.

Register