HP Forums

Full Version: New PRNG algorithm
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
One of the simple Pseudo Random Number Generators (PRNG) that I saw in HP-65 software manuals is:

r1 = frac(r0 * 997)

where r0 is the current random number, and r1 is the new one. It is simple and quite good. Recently I saw a similar variant:

r1 = frac(r0 * 147)

That got me curious. Since I was already doing a study on PRNGs (running several machines 24/7 to crunch random numbers using different variants of an algorithm), I decided to take a small detour and study a selection of numbers between 100 and 1000 (all ending in 7) that can do a better job than the version using the multiplier 997.

I am happy to report that the following two PRNGs do well:

r1 = frac(r0 * 127)


r1 = frac(r0 * 577)

While the version with the 127 multiplier is better than the one with the 557 multiplier, it sometimes hiccups and generates sequences that are slightly more auto-correlated.

For any of these Linear Congruential Generators, a good rule of thumb is to compute the sum of partial quotients of the multiplier and the modulus. A low sum implies low serial correlation. Cf. the Wiki on LCGs.
Reference URL's