HP41C random number generator help

12082017, 04:26 AM
(This post was last modified: 12082017 04:33 AM by Trond.)
Post: #21




RE: HP41C random number generator help
(12052017 12:30 PM)Namir Wrote: A good and simple algorithm (used by HP since the HP65 Stat Pacs) is:I tried a version of this while trying to avoid "bad seeds". I built a program that first checks if the variable 00 has anything above 0 beyond the fifth decimal point, and if not it adds pi, then goes on to multiply with 997, does FRC and STO 00. If 00 does have a digit at the fifth decimal it will simply do the last three steps. Looks to work fine for me, but it is no longer as simple of course. 

12082017, 07:43 PM
Post: #22




RE: HP41C random number generator help
(12082017 04:26 AM)Trond Wrote: I tried a version of this while trying to avoid "bad seeds". I built a program that first checks if the variable 00 has anything above 0 beyond the fifth decimal point, and if not it adds pi, then goes on to multiply with 997, does FRC and STO 00. If 00 does have a digit at the fifth decimal it will simply do the last three steps. Looks to work fine for me, but it is no longer as simple of course. Why don't you simply do it ...right? There is a clear definition of the minimal properties that have to be met: seven decimals, and the last one must be 1, 3, 7 or 9. This can be done with the following SEED code: Code: LBL"SEED" Enter a seed, XEQ "SEED", and if neccessary the input is corrected. Example: pi => 0,1415923 Yes, this simply sets the 7th decimal to 3 even if it was another valid digit like 1, 7 or 9 before. ;) Dieter 

12082017, 09:17 PM
(This post was last modified: 12082017 09:18 PM by Trond.)
Post: #23




RE: HP41C random number generator help
(12082017 07:43 PM)Dieter Wrote: Why don't you simply do it ...right? There is a clear definition of the minimal properties that have to be met: seven decimals, and the last one must be 1, 3, 7 or 9. This can be done with the following SEED code: I guess I missed the 1, 3, 7, 9 part, but yes I meant beyond the sixth decimal (do we have this written down somewhere? You seemed uncertain too). I was thinking not to change the seed if it's not necessary, but well, not sure how often it matters. But I also wanted to replace seeds that always predictably produce numbers that start with 0 in the first few decimals. Very small seeds will always start up with 0 in their first few decimals, and this includes the seed 0.0000003 which will be common (since the variable having a 0 stored is common). Having said that, my other random number generator program is working fine so, no big issue there. It was just a bit fascinating with the simplicity of multiplying with one number. 

12082017, 09:56 PM
(This post was last modified: 12082017 10:04 PM by Dieter.)
Post: #24




RE: HP41C random number generator help
(12082017 09:17 PM)Trond Wrote: I guess I missed the 1, 3, 7, 9 part, but yes I meant beyond the sixth decimal (do we have this written down somewhere? You seemed uncertain too). As already noted, an article in PPC Journal V4N8 by Victor K. Heyman takes a close look at four popular PRNGs, among them the 997x generator. The article mentions 11 different tests, even some quite sophisticated ones. Here it says: Quote:With the proper seed, this generator has a cylce of 500,000 iterations. HP chose pretty well when it selected .5284163. It is supposed to pass all standard tests, and with a blink or two, it does. That is a tough seed to remember, and worse to program, so I have found one that is as good and much easier on the user: Pi, Sin, Tan. It works, and also follows all the rules  the seed must have seven digits after multiplying by 997, the 7th not divisible by 2 or 5. (...) However every seed that meets the rule is not good. "Not divisible by 2 or 5" means 1, 3, 7 or 9 for the seed's last digit. And that's exactly what the 997x generator produces. Dieter 

12092017, 09:53 PM
Post: #25




RE: HP41C random number generator help
(12082017 07:43 PM)Dieter Wrote: Yes, this simply sets the 7th decimal to 3 even if it was another valid digit like 1, 7 or 9 before. ;) OKOK, here is a version that adjust the input only when required. Code: LBL "SEED997" Example: 0,1234567 XEQ"SEED997" => 0,1234567 0,2222222 XEQ"SEED997" => 0,2222223 Dieter 

12102017, 04:09 AM
Post: #26




RE: HP41C random number generator help
(12092017 09:53 PM)Dieter Wrote:(12082017 07:43 PM)Dieter Wrote: Yes, this simply sets the 7th decimal to 3 even if it was another valid digit like 1, 7 or 9 before. ;) Taking things as a challenge is a good thing! OK I will try this one. 

12212021, 06:25 AM
Post: #27




RE: HP41C random number generator help
Just thought I should add to this old thread that the HP55 statistics book recommends using seed plus Pi to the power of 5 [i.e. (S+π)^5], taking the fraction part of the formula.
The calculator does not have a fraction function, so I find the way they do it a bit interesting: find the whole integer part by doing +1E9 and then 1E9 (essentially letting the calculator cut off the fraction part by squeezing it out of the screen and memory), then subtracting this whole number from the rest. 

12212021, 07:09 PM
(This post was last modified: 12212021 07:10 PM by Mike T..)
Post: #28




RE: HP41C random number generator help
Quote:That is a tough seed to remember, and worse to program, Actually I find it very easy to remember, I don't think I've had to look it up once since 1977! (Once you spot the 'pattern' of the keys on the keypad and the symmetry involved you should see why it is easy to remember). Mike T. HP21, HP25, HP32E, HP33C, HP34C, HP10C, HP11C, HP12C, HP32S, HP22S 

12222021, 03:58 AM
Post: #29




RE: HP41C random number generator help
For calculators with 12 digits of precision, the following exact method will work (though the cycle is only 999,958). I can post a modification (which does double the time) to double the cycle length (though not the precision) later.
The seed is any nonzero integer. Recurrence: X(i) = X(i1) * 423621 mod 999959. X(i)/999959. Will be uniformly distributed on the open interval (01). 

12222021, 07:02 PM
Post: #30




RE: HP41C random number generator help  
« Next Oldest  Next Newest »

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