A simple algorithm for a strong PRNG. This PRNG math formula is George Marsaglia's multiply with carry. George Marsaglia was a mathematician and computer scientist. This passed all of the diehard battery of tests. The PRNG part is just 3 lines of code.
Code: Select all
'' Pseudo random number generator by Neil
'' The prng math formula is George Marsaglia's multiply with carry
'' This will fail any Practrand test. I only learned about Practrand after I posted it.
'' This passed all of the diehard battery of tests
'' This is a strong prng
dim as uinteger i,r1,r2
dim as ushort sr
'' 2 seed numbers from timer different numbers everytime
r2 = timer: r1 = r2 * 2
'' 2 seed numbers for same numbers every time on first run
'' r1 = 521288629:r2 = 3624316069
For i = 1 to 20
'' The magic is done with the next 3 lines of code
r1 = 36969 * (r1 and 65535) + (r1 shr 16)
r2 = 18000 * (r2 and 65535) + (r2 shr 16)
r1 = (r1 shl 16) + r2 ''r1 = large prng numbers
'' sr = small prng numbers 0 - 255
sr = (r1 mod 256)
print sr,r1
next
print
print i-1;" Random Numbers"
sleep