HP17b & it's offsprings - Random Number Generator - How?


Loooking into the "HP-17B Business Finance and Accounting (Step-by-Step Solutions)" on the new v7 DVD set which arrived today here in Germany (Thx. to Dave & all contributors!), I realized for the first time, that neither the keyboard nor the solver do offer a "Random Number" function.

One might argue: "If you didn't know it by now, you even might never need it ..." ;-)

Anyway. Could anybody recommend a good solver equation to generate random numbers?

Best regards,

Peter A. Gebhardt

Edited: 2 Dec 2009, 12:31 p.m.


Peter, this may not be exactly random, but in the absence of any timer function, I prompted the user to enter any old multi-digit number, then took LN of that and used FP and IP to get the first 2 digits after the decimal point. That gave me a number between 00 and 99, and that's what I wanted. Like I said, it may not be "purely" random, but I got what I needed.



Thx. for your quick response.

Best regards,

Peter A. Gebhardt


Halo, Peter; wie geht´s?

I was interrupted while writing my followup so I did not see Shepherd´s wise and practical suggestion. Anyway, you can search the MoHPC set and, under HP25 Applications or HP33/34 Applications and some others, you'll find many pseudo Random number generators. They mainly use an updated seed (which happens to be the last generated random number) to compute a new one. Although the HP28S has a RAND function (also a pseudo-number generator), it offered a way to enhance the randomizing process because it allowed the internal clock to be read and placed in the stack as a number, hence you could use this value as a seed to change the Random number. I am not sure if the HP17B has a time function which returns current clock as a number, but I know that it has a clock. If possible, you could use the current clock as a seed to generate a asynchronous pseudo Random series.

Hope this helps.

Luiz (Brazil)

Edited: 2 Dec 2009, 1:16 p.m.



Muito bom! Graças à sua ajuda.

Thank you. That's a good starting point.

Peter A. Gebhardt

PS: I must confess, I've cheated by using Google translate. Hopefully the translated sentence doesn't only look like Portuguese ... ;-)


Keine Problem, mein Freund.

I use AltaVista's Babel Fish Translator as a spell checker, but sometimes knowledge is not enough... So I have my non-English sentences corrected (the ones in English should need advise, though...)

If I could, I'd actually learn as many idioms as possible, because this is one of the main interests of mine since I was about 20 YO: communication with anyone with no language concerns. Did not have the chance then, trying to fulfill this 'need' of mine lately.

And here is one of the best places ever to find people from many places with a common interest and eager for sharing and learning.


Luiz (Brazilie)

PS: Yes, the sentence looks like Portuguese and can be understood.

Edited: 4 Dec 2009, 6:47 a.m.


slightly off-topic but pls. bear with me. On the SandMath I added a couple of functions written by Häkan Thörgren that make effective use of the 41C Time Module to create a true random seed, and a series of random numbers based on such.



Following up on the sources Luiz already named, James Soules for the HP Business Forums pointed me to the implementation of RAND within the HP-48:



R(n+1) = R(n) * 2851130928467 (mod 10^15)

Best regards,

Peter A. Gebhardt


Peter, Luis is right, the 17bii+ does have a clock and the solver has a CTIME function that returns the current time. For instance, at PM 9:13:28, if you enter equation A=CTIME and solve for A, A will be 21.1328, so you could probably use that number in some way to generate a random number rather than prompting the user to enter some number, which is never elegant.


With a little help from my friends (from this forum) ... :-)

(Example) Pseudorandom Generator for 17b

Uniform Distribution with Seed: RNDU = FP(9821*G(RNDU)+.211327) *) **) ***)
"True" Distribution w/o Seed: RAND = FP(9821*G(RAND)*CTIME+.211327)

Other approaches can be found by looking at


Best regards,

Peter A. Gebhardt

PS(2009, Dec 4th 23:49 MEZ): Or look here for indepth research on potentially useful algorithms


*) Credit for using these values goes to A.C.Rodríguez and his posting here on 11 Aug 2007 conc. 35s seed (Just found it by scanning the Forums Archive PDFs)


**) and it's original Author Jean-Marc Baillard here:


***) And even Microsoft EXCEL did use it - claiming it's good up to a million "draws", but failing statistical tests:


Edited: 8 Dec 2009, 5:08 p.m. after one or more responses were posted


Hi Peter. I entered your equations into my yellow / gold 17bii+ (s/n 61801536) and it doesn't seem to work. When I run either equation they return 0.211327. Either I have done something wrong or there is a difference between the 17b and 17bii+. Any ideas?





I've tested on a 17bII (s/n: 3610M00859) and a 17bII+ (gold, s/n: CNA42903649).

The only difference: the 17bII when started with seed == 0 in RNDU or RAND respectively, does return 0 at the first key press.

After pressing CALC do a CLR DATA first.

Best regards,

Peter A. Gebhardt


Peter, are you sure you tested on a 17bii+ unit? I got the same results as John, running on both the old 17bii+ (gold) and newer 17bii+ (retro silver). I haven't tested on my 17b or 17bii yet, but I have no doubt it will work on those because their solver works differently (that is, better) than the solver in the plusses. The plus solver has that problem with an extra pass at the beginning of the equation evaluation, and I'd bet that that is the reason your equations don't work, at least on John and my plus units.

Don Shepherd



in my HP17BII+ (gold, SN CN33015xxx), after pressing [CALC] the calculator returns [INVALID EQUATION] and the cursor stops at R in G(RAND). I checked the equation many times, added separators in all arithmetic operations, and the error is marked in the same place.

I´ll try with the HP17BII later.


Luiz (Brazil)



try to use a different variable name instead of RAND on both sides of the equation. If the error persists then you might have a problem because of the L() & G() issues with the early 17bII+'sses.

Checked s/n definition @Graig Finseth's site ( http://www.finseth.com/hpdata/serial.php ): ccywwnnnnn - your unit is apparently from 2003 and contains an older ROM version which was already reported of having problems in this area. Pls. scan the archives for more information.

There is another obvious problem with the 2nd formula which was pointed out by John already, but somewhat misinterpreted by me:

The uninitialized G(RAND) as long as it evaluates to 0 (zero) returns a fix SEED of .211327 for RAND ...

After you've entered the equations (or after an Error with L() & (G) as encountered here), pls. make sure that you CLR ALL variables while in SOLVE but not in CALC mode (clearing variables for ALL equations!)


Best regards,

Peter A. Gebhardt

Edited: 4 Dec 2009, 12:16 p.m.


Thanks Peter. It's still a "no-go" after trying different sequences using the CLR DATA function. I've decided that there must be differences in ROM's that keeps this from working correctly. :-(

Thanks and regards,



Here is a version that works on my 17bii+ (silver):

RNDU = L(SEED:FP(9821*SEED+.211327))
Solve for RNDU! Problem: RCL SEED should return the same value as RCL RNDU but it doesn't. Is the equation evaluated more than once?


Thanks Marcus, it works. I agree, I'm not sure what's going on with RCL SEED and RCL RNDU.




Is the equation evaluated more than once?

Yes, a minimum of two times, and more if it iterates, which it frequently does on the 17bii+'s. See article 830. The solver in the plusses does not work like the solver in the 17b or 17bii. It is illogical, and my attempts to ask HP to clarify exactly how it does work have not been successful. I'm convinced there is no one currently within HP who knows how the plus solver currently works.


But this still doesn't explain, why SEED and RNDU differ in value. If I set SEED to 0 and solve for RNDU, then RNDU is set to 0.2113... (the last constant in the expression) which I do expect, but SEED is set to a different value: 0,6538. I'm puzzled.


Marcus, you are right to be puzzled. If anyone at HP can diagnose this and is listening, we'd love to hear from you.


I tried running the self-test to see if it would report the ROM version at the end of the test but no luck. Are you aware of any sequence of button pushes that would provide this?



John, I just went through by 17bii+ "file" and I could not find any reference to a key sequence that will give you a version number or ROM number. If there is such a sequence, I'm not aware of it.




be careful using the selftest! It could clear your calc's memory and all your stored equations.

Look here for a description of keypresses:


Best regards,

Peter A. Gebhardt

Edited: 9 Dec 2009, 4:02 a.m.



But this still doesn't explain, why SEED and RNDU differ in value. If I set SEED to 0 and solve for RNDU, then RNDU is set to 0.2113... (the last constant in the expression) which I do expect, but SEED is set to a different value: 0,6538. I'm puzzled.

as expected above findings could not be reproduced on my 17bII+. My results:

Keys      Display
0 SEED SEED=0.0000
RNDU RNDU=0.2113
RNDU RNDU=0.6538
RNDU RNDU=0.1212

Best regards,

Peter A. Gebhardt


So you must have a different version of the solver in your machine. Mine is a silver (newer?) release.

Peter, your results look fine. You can simply use the formula and you will get the desired pseudo random sequence on your machine.



your solution does work only for a single SEED / RNDU combination. (On my Gold 17bII+)

Pressing RNDU a 2nd time shows a value outside 0 ... 1

Best regards,

Peter A. Gebhardt


I tested it with my silver 17bii+ and it looked correct. Can you set SEED to 0 and post the first few RNDU results here?

Keys      Display
0 SEED SEED=0.0000
RNDU RNDU=0.2113
RNDU RNDU=0.1222
RNDU RNDU=0.5160




Now I understand - you are using a 2-step process.

What I'm after is, storing the 'seed' (or even none) into RNDU once and then proceed (by only pressing RNDU again) to get the next value in sequence - and so on ...

Keys      Display

That's the way the formula in Message #10 works on both units of mine.
It does even work, if you use an initial RNDU outside { 0 ... 1 }

Best regards,

Peter A. Gebhardt

Edited: 8 Dec 2009, 6:19 p.m.


This is how it *should* work, but it doesn't do on the 17bii+. I tried to overcome the situation by adding the seed variable. Normally, the modified sequence should be identical to the original formula if you only set SEED once and press RNDU multiple times. Because of reasons yet to determine, this isn't the case on the "+". The formula gets evaluated twice with each step but returns the RNDU result of the first step. Therefore, SEED (checked with RCL SEED) and RNDU differ. If you can live with the fact that the formula returns every other result of the pseudo random sequence, just press RNDU in each step.

Possibly Related Threads...
Thread Author Replies Views Last Post
  HP Prime: RANDOM Alberto Candel 4 768 10-18-2013, 09:18 PM
Last Post: Alberto Candel
  Some random wish list items for the 43s Marcel Samek 18 2,068 07-11-2013, 05:35 PM
Last Post: Paul Dale
  HP-41C Overlay Generator (by spb) aurelio 0 370 03-06-2013, 07:49 AM
Last Post: aurelio
  HP28S screen noise generator Keith Midson 7 941 02-19-2012, 05:35 PM
Last Post: Gilles Carpentier
  OT: Help with Testing Random Number Generators Namir 5 795 08-01-2011, 11:20 PM
Last Post: Paul Dale
  Question about random number generators Namir 20 1,828 07-08-2011, 11:05 AM
Last Post: David Hayden
  HP-41C Overlay Generator spb 26 2,289 04-22-2011, 07:41 PM
Last Post: spb
  Evolution of the HP17B - prototype to current in pictures Keith Midson 10 1,099 12-06-2010, 06:10 AM
Last Post: Keith Midson
  Random Number Generation Challenge (sort of) Namir 9 1,137 02-15-2010, 08:05 AM
Last Post: Bart (UK)
  Barcode generator for Optical Wand? Timo 2 503 02-14-2010, 04:16 PM
Last Post: Timo

Forum Jump: