(12C) Two Random Generator Comparison - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (12C) Two Random Generator Comparison (/thread-11118.html) |
(12C) Two Random Generator Comparison - Gamo - 07-25-2018 10:47 AM This program compare the two "Random Number Generator" by the use of "Accumulate Statistic" Then get the " Average" result from both random generator. 1st Random Generator used: e^(X+Pi) FRAC 2nd Random Generator used: (X*997) FRAC Second Generator used the result from the First generator as a seed. Both generate 6 Digits Random Number then store [Σ+] Program use the Counter to provide the amount of count to generate. Remark: I noticed that there many discussion about Random Generator in this forum. This program is a rough comparison only and by mean of the use of the Statistic Average. The result average I mostly see is around 450,000 to 550,000 range. So this program is good for observation to see the many different result depending on specific count. See for yourself !!! Example: Clear [Σ] // must clear statistic register for any new start Example below will give different result each time. First try small count. Let's try 100 times 100 [R/S] Display briefly show 0,00000000 indicate that almost done 506,951 // 2nd Average Random result [X<>Y] 485,063 // 1st Average Random result 5000 [R/S] Display briefly show 0,000000000 499,077 // 2nd Average Random result [X<>Y] 507,235 // 1st Average Random result For very large count it is best to use the 12C+ or Emulator. I have try one million count and took about 3-4 minute on Android 12C app Program: Compare two Random Generator Code:
RE: (12C) Two Random Generator Comparison - Joe Horn - 07-25-2018 12:15 PM Speed suggestion: Since we're only interested in the average, adding the random numbers on the stack and dividing by the loop count would run much faster than using the Σ+ function which does a lot more than sum the X's. RE: (12C) Two Random Generator Comparison - Gamo - 07-26-2018 12:07 AM Thanks Joe I'll make an update soon. Gamo RE: (12C) Two Random Generator Comparison - Gamo - 07-26-2018 10:48 AM Here is the updated version without the use of the Statistic Register. Procedure to run this program is the same as above. Don't forget to clear REG each time for a new run. Program: Compare Two Random Number Generator Code:
Gamo RE: (12C) Two Random Generator Comparison - Dieter - 07-26-2018 06:03 PM (07-25-2018 10:47 AM)Gamo Wrote: This program compare the two "Random Number Generator" by using the "Accumulate Statistic" Gamo: sorry, but this does not work. You cannot use the result of one RNG as the input of another one as this does not return what the second RNG should. Instead you actually get the results of a third, different RNG which here in this case is \(\large x_{n+1} = frac(997 \cdot frac(e^{x_n+\pi})) \) (Well, not quite, as the result is not the input of the first RNG again) Also the mean does not say much about a RNG. Consider a RNG that returns 0,5 0,5 0,5 0,5 0,5... or 0,4 0,6 0,4 0,6... All this gives a perfect 0,5 as the mean. Although the sequence sure is not random at all. The following program is different from yours in these points:
Code: 01 STO 0 Example: 0,1234567 [STO] 7 [STO] 8 1000 [R/S] ... 0 g [\(\bar{x}\)] => 0,4855 [X<>Y] 0,5002 g [\(s\)] => 0,2898 [X<>Y] 0,2888 Of course the \(\bar{x}\) and \(s\) calculation could also be done by the program, but when the user invokes these functions he always knows which value he gets. And it doesn't require more than pressing a key. Dieter __________ * Yes, the calculated (sample) standard deviation actually is slightly less by a factor of sqrt((n–1)/n) but for large sample sizes this does not make much of a difference. RE: (12C) Two Random Generator Comparison - Thomas Klemm - 07-27-2018 07:27 AM (07-26-2018 06:03 PM)Dieter Wrote: * Yes, the calculated (sample) standard deviation actually is slightly less by a factor of sqrt((n–1)/n) but for large sample sizes this does not make much of a difference. Or then you just add the mean before calculating the standard deviation:
RE: (12C) Two Random Generator Comparison - Dieter - 07-27-2018 11:42 AM (07-27-2018 07:27 AM)Thomas Klemm Wrote:(07-26-2018 06:03 PM)Dieter Wrote: * Yes, the calculated (sample) standard deviation actually is slightly less by a factor of sqrt((n–1)/n) but for large sample sizes this does not make much of a difference. That's a good idea. This also leaves the mean unaffected so that both [\(\bar{x}\)] and [\(s\)] return the desired results, i.e. mean and population standard deviation. To implement this idea simply replace line 21 (GTO 00) with GTO 37 and add this: Code: 37 x-bar This way the example with seed = 0,1234567 returns g [\(\bar{x}\)] => 0,4855 [X<>Y] 0,5002 g [\(s\)] => 0,2897 [X<>Y] 0,2886 So for this seed (!) the second RNG almost perfectly matches the theoretical values. Also these results are not very different from the original ones with the sample standard deviation. Rule of thumb: For 10n random numbers the results agree in n decimals. In this case, with 10³ numbers, in the first three (0,290 and 0,289). Dieter |