Last active
August 29, 2015 14:13
-
-
Save samisalkosuo/203a580a9c7e901377e7 to your computer and use it in GitHub Desktop.
Multiply-with-carry pseudo random number generator by George Marsaglia. Code from: http://en.wikipedia.org/wiki/Random_number_generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m_w = 0x46ab2f73d #must not be zero, nor 0x464fffff | |
m_z = 0xa368bbec #must not be zero, nor 0x9068ffff | |
def mwc(): | |
global m_w | |
global m_z | |
m_z = 36969 * (m_z & 65535) + (m_z >> 16) | |
m_w = 18000 * (m_w & 65535) + (m_w >> 16) | |
return (m_z << 16) + m_w #32-bit result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment