MWC256, Very high quality PRNG with RealRandom seed, save a COG.
Heater.
Posts: 21,230
Attached is an implementation of George Marsaglia's MWC256 Pseudo Random Number Generator (PRNG) algorithm in Spin.
This PRNG has a period of about 2 to the power 8222. Which means the number of pseudo random numbers you can pull from it before it starts to repeat itself is a decimal number far to big to write down in this post!
It is a good source of effectively random numbers whilst saving the COG one might otherwise use for the RealRandom object. Using RealRandom briefly at start up to seed the thing ensures a different sequence on each run and saves a COG.
This is a follow on from the JKISS32 PRNG I posted recently with a much longer period but it has some down sides:
1) It requires 256 LONGs of internal state information which one may not want to spend on a PRNG in a full Propeller.
2) The algorithm requires unsigned arithmetic on 64 bit numbers which does not suit Spin and makes it far slower than JKISS32.
I have tested this against George's C version for a million numbers and it seems to be correct.
Big thanks to Phil Pilgrim for his umath object which I have adapted for MWC256 here. And to Kuroneko for pointing me at it.
So now all the Propeller super computer users out there have a high quality PRNG for their long running Monte Carlo simulations.
Me, I'm just going to twinkle the LEDs on my Christmas tree with it next year:)
This PRNG has a period of about 2 to the power 8222. Which means the number of pseudo random numbers you can pull from it before it starts to repeat itself is a decimal number far to big to write down in this post!
It is a good source of effectively random numbers whilst saving the COG one might otherwise use for the RealRandom object. Using RealRandom briefly at start up to seed the thing ensures a different sequence on each run and saves a COG.
This is a follow on from the JKISS32 PRNG I posted recently with a much longer period but it has some down sides:
1) It requires 256 LONGs of internal state information which one may not want to spend on a PRNG in a full Propeller.
2) The algorithm requires unsigned arithmetic on 64 bit numbers which does not suit Spin and makes it far slower than JKISS32.
I have tested this against George's C version for a million numbers and it seems to be correct.
Big thanks to Phil Pilgrim for his umath object which I have adapted for MWC256 here. And to Kuroneko for pointing me at it.
So now all the Propeller super computer users out there have a high quality PRNG for their long running Monte Carlo simulations.
Me, I'm just going to twinkle the LEDs on my Christmas tree with it next year:)
zip
16K