Post Reply 
Random number generator in HP 30S
02-19-2017, 08:02 AM (This post was last modified: 02-19-2017 08:04 AM by Joe Horn.)
Post: #1
Random number generator in HP 30S
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.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
02-19-2017, 01:03 PM
Post: #2
RE: Random number generator in HP 30S
I can only confirm no way to seed RANDM.
Find all posts by this user
Quote this message in a reply
02-19-2017, 03:06 PM
Post: #3
RE: Random number generator in HP 30S
(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...


Attached File(s)
.pdf  30Srandom.pdf (Size: 153.71 KB / Downloads: 40)

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
02-19-2017, 09:32 PM
Post: #4
RE: Random number generator in HP 30S
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.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
02-19-2017, 10:22 PM
Post: #5
RE: Random number generator in HP 30S
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
Find all posts by this user
Quote this message in a reply
02-20-2017, 09:14 PM
Post: #6
RE: Random number generator in HP 30S
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.
Find all posts by this user
Quote this message in a reply
02-20-2017, 10:23 PM
Post: #7
RE: Random number generator in HP 30S
(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!

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)