Good news for PPC RandomNumber Generator

05172021, 07:51 PM
Post: #1




Good news for PPC RandomNumber Generator
Hi All,
I was reading in the PPC ROM manual and found the label RN that generates random numbers. The PPC ROM manual documents the algorithm used to generate random numbers. I happen to find a randomnumber testing function in Matalb. I wrote a Matlab function that implements the PPC RN routine and ran a test by generating 1 million random numbers. The PPC RN passed the randomness test with flying colors!! :) Namir 

05172021, 09:01 PM
(This post was last modified: 05172021 09:02 PM by Gene.)
Post: #2




RE: Good news for PPC RandomNumber Generator
New Seed = Fractional part ( Previous Seed x 9821 + 0.211327 )
Where seed is a decimal number. This is also the random number generator we put into the 67 FUN rom. Gene 

05172021, 09:19 PM
Post: #3




RE: Good news for PPC RandomNumber Generator  
05172021, 10:56 PM
Post: #4




RE: Good news for PPC RandomNumber Generator
Out of curiosity, how does the good old 997 PRNG hold up in the same Matlab test?


05172021, 11:03 PM
Post: #5




RE: Good news for PPC RandomNumber Generator  
05172021, 11:03 PM
Post: #6




RE: Good news for PPC RandomNumber Generator
Namir,
Matlab uses double precision floating point by default, does the algorithm still pass if limited to single precision or HP41 precision? Try CC41! 

05172021, 11:35 PM
Post: #7




RE: Good news for PPC RandomNumber Generator
(05172021 11:03 PM)Craig Bladow Wrote: Matlab uses double precision floating point by default, does the algorithm still pass if limited to single precision or HP41 precision? Algorithm is really LCG, disguised as floating points. Example, we can rewrite it this way (initial seed in units of millionth) Code: function make_rnd(seed) lua> rnd = make_rnd(123456)  seed 0.123456 lua> rnd(), rnd(), rnd(), rnd(), rnd() 0.672703 0.82749 0.990617 0.060884 0.153091 Seed calculations are integer based, without rounding errors. 

05172021, 11:50 PM
(This post was last modified: 05182021 01:02 AM by Valentin Albillo.)
Post: #8




RE: Good news for PPC RandomNumber Generator
.
That simple algorithm produces exactly one million pseudorandom integers from 0 to 999999 (or from 0.000000 to 0.999999). After that, it simply repeats the same sequence, which is fine for games and such. I used it to generate 1,000,000 userselectable random palettes for my Fractval program. On the other hand, the HP71B RND function provides a trillion rng's before repeating and passes the Spectral test, which is adequate for serious purposes. Just a onemillion period is too few for that, the longer the period the better. V. All My Articles & other Materials here: Valentin Albillo's HP Collection 

05182021, 03:13 AM
Post: #9




RE: Good news for PPC RandomNumber Generator  
05182021, 03:15 AM
(This post was last modified: 05182021 03:16 AM by Namir.)
Post: #10




RE: Good news for PPC RandomNumber Generator
(05172021 11:03 PM)Craig Bladow Wrote: Namir, I don't know. But let me ask which HP41C application will need to generate more than a million random number? Namir 

05182021, 06:02 AM
Post: #11




RE: Good news for PPC RandomNumber Generator
(05172021 11:03 PM)Sylvain Cote Wrote:(05172021 09:01 PM)Gene Wrote: New Seed = Fractional part ( Previous Seed x 9821 + 0.211327 )Same number generator used in the HP41 GAMES PAC (LBL "RNDM") Yep! That's an old friend. Greetings, Massimo +×÷ ↔ left is right and right is wrong 

05182021, 10:35 AM
Post: #12




RE: Good news for PPC RandomNumber Generator
I also tested the following algorithms that were mentioned in HP documentations:
f = frac((pi+ r)^3) > failed randomness test f = frac((pi+ r)^5) > passed randomness test Namir 

05192021, 01:48 AM
Post: #13




RE: Good news for PPC RandomNumber Generator
(05182021 03:15 AM)Namir Wrote:(05172021 11:03 PM)Craig Bladow Wrote: Namir, The application that tests if there are 1,000,000 unique numbers from this algorithm? Try CC41! 

05192021, 02:18 AM
Post: #14




RE: Good news for PPC RandomNumber Generator
(05182021 03:15 AM)Namir Wrote: But let me ask which HP41C application will need to generate more than a million random number? This 98step RPN program generates and uses half a million random numbers in the included worked example and would obtain greater accuracy if using several million, matter of fact I ran it using 100 million random values. It wouldn't obtain such accuracy if using a generator with shorter period, the results would be unacceptably biased and thus useless. V. All My Articles & other Materials here: Valentin Albillo's HP Collection 

05192021, 03:29 AM
(This post was last modified: 05192021 03:35 AM by Namir.)
Post: #15




RE: Good news for PPC RandomNumber Generator
(05192021 01:48 AM)Craig Bladow Wrote:(05182021 03:15 AM)Namir Wrote: I don't know. But let me ask which HP41C application will need to generate more than a million random number? In Matlab I sorted the million random numberand checked each number with the next 1000 numbers. There were no matches! 

05192021, 01:20 PM
Post: #16




RE: Good news for PPC RandomNumber Generator
(05192021 03:29 AM)Namir Wrote:(05192021 01:48 AM)Craig Bladow Wrote: The application that tests if there are 1,000,000 unique numbers from this algorithm? I ran it on a DM41X in FAST mode, plugged into USB power, and after many hours it let me know there was a repeat of the initial seed after 1,000,000 unique numbers. Try CC41! 

05192021, 03:18 PM
Post: #17




RE: Good news for PPC RandomNumber Generator
(05172021 09:01 PM)Gene Wrote: New Seed = Fractional part ( Previous Seed x 9821 + 0.211327 ) Not to mention the HP41C Standard Applications book. I'd think this would be the bestknown PRNG among HP41 veterans. Page 24: Quote:Another interesting portion of this program is the random number generator: 

05192021, 03:23 PM
Post: #18




RE: Good news for PPC RandomNumber Generator
(05192021 01:20 PM)Craig Bladow Wrote:(05192021 03:29 AM)Namir Wrote: In Matlab I sorted the million random numberand checked each number with the next 1000 numbers. There were no matches! Try it in Free42, it will run orders of magnitude faster. Free42, though a simulator with far greater accuracy, exactly mimics the HP71B 12digit RND results, I tried both RAN vs RND sequences for 100 mllion random numbers and they matched perfectly. V. All My Articles & other Materials here: Valentin Albillo's HP Collection 

05192021, 05:41 PM
Post: #19




RE: Good news for PPC RandomNumber Generator
On these extended test runs to verify generated numbers are not repeated, where are all the generated numbers stored, while verifying subsequent numbers don't match, or are you trusting some algorithm's verification?
Not prodding here, I really don't know. Bob Prosperi 

05192021, 06:31 PM
Post: #20




RE: Good news for PPC RandomNumber Generator
(05192021 05:41 PM)rprosperi Wrote: On these extended test runs to verify generated numbers are not repeated, where are all the generated numbers stored, while verifying subsequent numbers don't match, or are you trusting some algorithm's verification For this particular algorithm and others like it, if the initial seed ever gets repeated then the whole sequence repeats again so a simple verification requires just to compare each generated number to the initial seed while keeping count of how many numbers are generated. Here, any seed you care to use gets repeated after exactly one millon generated numbers. No need to store anything but the initial seed. To make sure there are no seeds which result in shorter periods, there are more ellaborated yet still simple algorithms that also don't need storing the whole sequence, see this link, "cycle detection". Best regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection 

« Next Oldest  Next Newest »

User(s) browsing this thread: