Skip to content

Instantly share code, notes, and snippets.

@samisalkosuo
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samisalkosuo/203a580a9c7e901377e7 to your computer and use it in GitHub Desktop.
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
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