The Museum of HP Calculators

HP Forum Archive 10

[ Return to Index | Top of Index ]

hp 20s RNG
Message #1 Posted by John on 20 Feb 2003, 4:05 p.m.

Hello All: I'm using a HP 20S, I know, please forgive, without RPL. I have tried very hard with a limited math backgound to add lines to the Random Number Generator Sample Program (pgs 75-76 owners manual) to constuct a Scaled Random Number Generator with no sucess. I have been using 101 and 0 for the upper and lower limits and adding that command to either the eighth and ninth command lines with no success. Yes, I know I am a biologist and shouldn't wonder far that science but I want to because this calcualtor is cool and more mobile than a computer.

      
Re: hp 20s RNG
Message #2 Posted by eg on 20 Feb 2003, 6:55 p.m.,
in response to message #1 by John

John,

If you store the lower limit in register 1 and the upper limit in register 2, then the following code should work for you. Note that the first nine lines are the same as in the manual. The extra lines are added to the end.

For the example you gave, store 0 in register 1 and store 101 in register 2 before calling the program with XEQ A. Each time you hit XEQ A, you will get another random number in the range defined by the numbers in register 1 and register 2.

Also, if this is the only program in memory, you can make sure that it is entered correctly by looking at the checksum, which should be 0xd229. Press SHOW when in program mode to display the checksum.

-eg.

< Original Code in the manual > 01 LBL A 02 RCL 0 03 x 04 9 05 9 06 7 07 = 08 FP 09 STO 0

< New code that returns a random number in the range defined by register 1 and register 2 > 10 RCL 2 11 - 12 RCL 1 13 = 14 x 15 RCL 0 16 + 17 RCL 1 18 = 19 RTN


[ Return to Index | Top of Index ]

Go back to the main exhibit hall