HP41C random number generator help
12-05-2017, 08:23 AM (This post was last modified: 12-05-2017 06:56 PM by Dieter.)
Post: #8
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: HP41C random number generator help
(12-05-2017 05:45 AM)Trond Wrote:  So this program takes the natural logarithm of whatever is in you x stack register,

It it supposed to take the ln of the previous random number. This is how pseudo random number generators work: they calculate the next number from the last one.

(12-05-2017 05:45 AM)Trond Wrote:  and I am a bit uncertain what the E2 does here? And should I just type it as it stands, or do they mean e^2 (but that would be typed 2 E^X)?

As already noted, this is a shortcut for 1E2 or simply 100. With a bit of synthetic programming the leading "1" can be removed, saving one byte. If you happen to see a line with a single "E" that's the same thing, just the nerd way of writing a simple "1". ;-)

(12-05-2017 05:45 AM)Trond Wrote:  I tried one of the other programs too, but it did not return numbers between 0 and 1.

?!? What "other programs"?

The last step of most PRNGs is a FRC command. This removes the integer part and leaves only the decimals, so you automatically get something between 0 and (less than) 1.

Random number generators have been discussed here several times, just do a search and you'll find some suggestions. You may also take a look at PPC Journal V4N8 and V8N3.

The following examples assume the current random number (the seed) in R00.

This one is fast and good enough for games and similar purposes. I use it in most of my programs.

Code:
RCL 00 Pi + x² FRC STO 00

This one is supposed to have a somewhat better number distribution:

Code:
RCL 00 Pi + ENTER x² * FRC STO 00
Edit: replaced x5 with x3.

The following generator was used in early HP programs, but best results are only obtained if the seed has certain properties. And it obviously does not work with a seed of zero.

Code:
RCL 00 997 * FRC STO 00

And finally this one, already mentioned by others, has good statistical properties and produces six-digit random numbers. It runs faster if you store the two constants in data registers.

Code:
RCL 00 9821 * ,211327 + FRC STO 00

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread HP41C random number generator help - Trond - 12-05-2017, 05:45 AM RE: HP41C random number generator help - Paul Dale - 12-05-2017, 05:52 AM RE: HP41C random number generator help - Trond - 12-05-2017, 06:02 AM RE: HP41C random number generator help - Paul Dale - 12-05-2017, 06:06 AM RE: HP41C random number generator help - Dieter - 12-05-2017, 08:31 AM RE: HP41C random number generator help - Sylvain Cote - 12-05-2017, 06:08 AM RE: HP41C random number generator help - Trond - 12-05-2017, 06:33 AM RE: HP41C random number generator help - Trond - 12-05-2017, 10:25 PM RE: HP41C random number generator help - Trond - 12-05-2017, 06:12 AM RE: HP41C random number generator help - Dieter - 12-05-2017 08:23 AM RE: HP41C random number generator help - Namir - 12-05-2017, 12:30 PM RE: HP41C random number generator help - Trond - 12-05-2017, 03:24 PM RE: HP41C random number generator help - Dieter - 12-05-2017, 06:54 PM RE: HP41C random number generator help - Trond - 12-05-2017, 07:50 PM RE: HP41C random number generator help - Dieter - 12-05-2017, 08:11 PM RE: HP41C random number generator help - Trond - 12-08-2017, 04:26 AM RE: HP41C random number generator help - Dieter - 12-08-2017, 07:43 PM RE: HP41C random number generator help - Trond - 12-08-2017, 09:17 PM RE: HP41C random number generator help - Dieter - 12-08-2017, 09:56 PM RE: HP41C random number generator help - Mike T. - 12-21-2021, 07:09 PM RE: HP41C random number generator help - Dieter - 12-09-2017, 09:53 PM RE: HP41C random number generator help - Trond - 12-10-2017, 04:09 AM RE: HP41C random number generator help - ttw - 12-05-2017, 01:43 PM RE: HP41C random number generator help - Trond - 12-05-2017, 03:53 PM RE: HP41C random number generator help - Thomas Okken - 12-05-2017, 05:21 PM RE: HP41C random number generator help - Trond - 12-05-2017, 06:32 PM RE: HP41C random number generator help - Garth Wilson - 12-05-2017, 07:33 PM RE: HP41C random number generator help - Trond - 12-21-2021, 06:25 AM RE: HP41C random number generator help - ttw - 12-22-2021, 03:58 AM RE: HP41C random number generator help - John Keith - 12-22-2021, 07:02 PM