HP41C random number generator help

12052017, 08:23 AM
(This post was last modified: 12052017 06:56 PM by Dieter.)
Post: #8




RE: HP41C random number generator help
(12052017 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. (12052017 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". ;) (12052017 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 This one is supposed to have a somewhat better number distribution: Code: RCL 00 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 And finally this one, already mentioned by others, has good statistical properties and produces sixdigit random numbers. It runs faster if you store the two constants in data registers. Code: RCL 00 Dieter 

« Next Oldest  Next Newest »

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