Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are much better choices than Mersenne Twister nowadays. Here is a RNG called WELL512, designed by the designers of Mersenne, developed 10 years later, and an all around better choice for games. The code is put in the public domain by Dr. Chris Lomont. He claims this implementation is 40% faster than Mersenne, does not suffer from poor diffusion and trapping when the state contains many 0 bits, and is clearly a lot simpler code. It has a period of 2^512; a PC takes over 10^100 years to cycle through the states, so it is large enough.</p> <p>Here is a paper overviewing PRNGs where I found the WELL512 implementation. <a href="http://www.lomont.org/Math/Papers/2008/Lomont_PRNG_2008.pdf" rel="noreferrer">http://www.lomont.org/Math/Papers/2008/Lomont_PRNG_2008.pdf</a></p> <p>So - faster, simpler, created by the same designers 10 years later, and produces better numbers than Mersenne. How can you go wrong? :)</p> <p><strong>UPDATE (11-18-14)</strong>: Fixed error (changed 0xDA442D20UL to 0xDA442D24UL, as described in the paper linked above).</p> <pre><code>/* initialize state to random bits */ static unsigned long state[16]; /* init should also reset this to 0 */ static unsigned int index = 0; /* return 32 bit random number */ unsigned long WELLRNG512(void) { unsigned long a, b, c, d; a = state[index]; c = state[(index+13)&amp;15]; b = a^c^(a&lt;&lt;16)^(c&lt;&lt;15); c = state[(index+9)&amp;15]; c ^= (c&gt;&gt;11); a = state[index] = b^c; d = a^((a&lt;&lt;5)&amp;0xDA442D24UL); index = (index + 15)&amp;15; a = state[index]; state[index] = a^b^d^(a&lt;&lt;2)^(b&lt;&lt;18)^(c&lt;&lt;28); return state[index]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload