samedi 23 mai 2020

How is mt19937 prng exactly used for python random module functions?

from random import *
seed(5489)
hex(getrandbits(32)) # '0xc9a0e034'
hex(getrandbits(32)) # '0x38feb21f'

I ran this with Python 3.8.2 (not that it should matter too much). This is not what I would expect from a MT19937 32 bit PRNG. To be exact, I was expecting values similar to the ones presented in this website: https://create.stephan-brumme.com/mersenne-twister/

What is Python doing differently from other languages? Is there a way that I could reproduce the bits generated by Python myself? (Also, how is the random() float from 0 to 1 generated, from the 32-bit word sized integers?)

Thanks!




Aucun commentaire:

Enregistrer un commentaire