Post Reply 
(12C) Two Random Generator Comparison
07-25-2018, 10:47 AM (This post was last modified: 07-26-2018 02:04 PM by Gamo.)
Post: #1
(12C) Two Random Generator Comparison
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:

01 ENTER
02 X<>Y
03 STO 0
04 RCL 0
05 X=0 ?
06 GTO 45
07 RCL 7
08   3
09   5
10   5
11 ENTER
12   1
13   1
14   3
15   ÷
16   +
17 e^x
18 FRAC
19 STO 7
20   9
21   9
22   7
23   x
24 FRAC
25 EEX
26   6
27   x
28   1
29   +
30 INTG
31 STO 8
32 RCL 7
33 EEX
34   6
35   x
36   1
37   +
38 INTG
39 RCL 8
40 Σ+
41 CLx
42   1
43 STO-0
44 GTO 04
45   0
46 FIX 9
47 PSE
48 FIX 0
49 X bar
50 GTO 00
Find all posts by this user
Quote this message in a reply
07-25-2018, 12:15 PM
Post: #2
RE: (12C) Two Random Generator Comparison
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.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
07-26-2018, 12:07 AM
Post: #3
RE: (12C) Two Random Generator Comparison
Thanks Joe

I'll make an update soon.

Gamo
Find all posts by this user
Quote this message in a reply
07-26-2018, 10:48 AM (This post was last modified: 07-26-2018 10:54 AM by Gamo.)
Post: #4
RE: (12C) Two Random Generator Comparison
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:

01 ENTER
02 X<>Y
03 STO 0
04 STO 1
05 RCL 0
06 X=0 ?
07 GTO 44
08 RCL 2
09   3
10   5
11   5
12 ENTER
13   1
14   1
15   3
16   ÷
17   +
18 e^x
19 FRAC
20 STO 2
21 EEX
22   6
23   x
24   1
25   +
26 INTG
27 STO+3
28 RCL 2
29   9
30   9
31   7
32   x
33 FRAC
34 EEX
35   6
36   x
37   1
38   +
39 INTG
40 STO+4
41   1
42 STO-0
43 GTO 05
44   0
45 FIX 9
46 PSE
47 FIX 0
48 RCL 3
49 RCL 1
50   ÷
51 RCL 4
52 RCL 1
53   ÷
54 GTO 00

Gamo
Find all posts by this user
Quote this message in a reply
07-26-2018, 06:03 PM (This post was last modified: 07-26-2018 06:47 PM by Dieter.)
Post: #5
RE: (12C) Two Random Generator Comparison
(07-25-2018 10:47 AM)Gamo Wrote:  This program compare the two "Random Number Generator" by using the "Accumulate Statistic"
and 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.

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:
  • The two RNGs are working independently now. The results are not scaled, so the output is between 0 and 1.
  • You can (and should) store a seed for each RNG in R7 and R8 respectively.
    This is especially important for the 997-RNG. Here the seed should have 7 decimals where the last digit is either 1, 3, 7 or 9.
  • The constants \(\pi\) and 997 are prestored in R9 and R ,0 for faster execution.
  • The summation registers are cleared by the program, the user does not have to care about this.
  • The program does not return any value. Instead you can simply press [\(\bar{x}\)] or [\(s\)] afterwards to get the two means and standard deviations.
The expected mean is 0,5 and the expected standard deviation is sqrt(1/12) = 0,2886... *

Code:
01 STO 0
02 Clear Σ
03 3
04 ,
05 1
06 4
07 1
08 5
09 9
10 2
11 6
12 5
13 4
14 STO 9
15 9
16 9
17 7
18 STO ,0
19 RCL 0
20 X=0?
21 GTO 00
22 RCL 8
23 RCL ,0
24 x
25 FRAC
26 STO 8
27 RCL 7
28 RCL 9
29 +
30 e^x
31 FRAC
32 STO 7
33 Σ+
34 1
35 STO-0
36 GTO 19

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.
Find all posts by this user
Quote this message in a reply
07-27-2018, 07:27 AM
Post: #6
RE: (12C) Two Random Generator Comparison
(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:
  • [\(\bar{x}\)]
  • [\(\Sigma+\)]
  • [\(s\)]
Find all posts by this user
Quote this message in a reply
07-27-2018, 11:42 AM (This post was last modified: 07-27-2018 12:15 PM by Dieter.)
Post: #7
RE: (12C) Two Random Generator Comparison
(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.

Or then you just add the mean before calculating the standard deviation:
  • [\(\bar{x}\)]
  • [\(\Sigma+\)]
  • [\(s\)]

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
38 Σ+
39 CLX
40 GTO 00

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
Find all posts by this user
Quote this message in a reply
Post Reply 




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