HP Forums
Random number generator in HP 30S - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: Random number generator in HP 30S (/thread-7794.html)



Random number generator in HP 30S - Joe Horn - 02-19-2017 08:02 AM

Anybody know which pseudo-random number generator is used in the HP 30S? It seems to be a very poor generator, since RANDM*2^16 always returns integers (that's sad) which alternate between even and odd (also sad). The 30S doesn't let you seed the generator; even clearing the calculator doesn't restart the generator at a predictable place in its sequence. Any insights that you have about the 30S's random number generator would be greatly appreciated.


RE: Random number generator in HP 30S - Gerald H - 02-19-2017 01:03 PM

I can only confirm no way to seed RANDM.


RE: Random number generator in HP 30S - rprosperi - 02-19-2017 03:06 PM

(02-19-2017 08:02 AM)Joe Horn Wrote:  Any insights that you have about the 30S's random number generator would be greatly appreciated.

The attached Learning Module from HP confirms the seed is taken from the internal clock, and while otherwise does not seem to explain the algorithm, could provide insights. I'll leave the attachment up for a few days...


RE: Random number generator in HP 30S - Joe Horn - 02-19-2017 09:32 PM

Thanks, Bob. It would therefore seem that nobody knows what the 30S's pseudo-random number generator is. However, is there a way (without being John Nash) to take the integer sequence generated by RANDM*2^16 and find that sequence's generator?

Meanwhile, it should probably be noted somewhere that the RANDM function in the HP 30S should NOT be used for anything that requires a large cycle. RANDM only outputs 65536 different values. Therefore using it, for example, to pick a winning sweepstakes ticket number between 1 and 1 million would be grossly unfair, since over 93% of those ticket numbers would have zero probability of being picked.

Strange that RANDM*65536 generates integers that alternate between even and odd, whereas RANDMI(0,65535) does not.


RE: Random number generator in HP 30S - Paul Dale - 02-19-2017 10:22 PM

It is possible that there is more going on behind the scenes and that the period is greater than 216. Still, alternating odd/even is pretty bad.

- Pauli


RE: Random number generator in HP 30S - ttw - 02-20-2017 09:14 PM

The alternating odd-even behavior might indicate a linear congruential generator with 2^16 modulus. If you can look at the output in binary, a clue would be that the lowest order bit alternates; the second lowest bit has a cycle of 4; the third order has a cycle of 8, etc. For a cycle of length 2^16, there are algorithms that can determine the parameters; Google can probably find them.


RE: Random number generator in HP 30S - Joe Horn - 02-20-2017 10:23 PM

(02-20-2017 09:14 PM)ttw Wrote:  The alternating odd-even behavior might indicate a linear congruential generator with 2^16 modulus.

That's what I strongly suspect.

(02-20-2017 09:14 PM)ttw Wrote:  If you can look at the output in binary, a clue would be that the lowest order bit alternates; the second lowest bit has a cycle of 4; the third order has a cycle of 8, etc.

Aha! You're right! Sequential executions of RANDM*2^16, converted to binary, always exhibit the behavior you describe, but only the last 3 bits. All the higher-order bits seem random.

(02-20-2017 09:14 PM)ttw Wrote:  For a cycle of length 2^16, there are algorithms that can determine the parameters; Google can probably find them.

Time to go hunting! This is exciting!