Friday, March 13, 2020

Casio fx-9860g and fx-CG 50: Psuedorandom Numbers

Casio fx-9860g and fx-CG 50:  Psuedorandom Numbers

Introduction:  Generating Random Integers

The program PSUEDORN generates random integers by using the recurring relationship:

R_n+1 = (R_n * A + C) mod M

where R_0 = S, the seed
A = multiplier
M = modulus
C = increment

Outputs:

List 5:  list of integers generated.  If the list cycles, then the numbers return and we don't have a good random sample.

List 6:  percentile list of 10 elements, which each element represents a 10 percentile.  The best parameters will have elements of List 6 of around 0.1 uniformly.

List 6 =
{ 0% - 10% tile, 10% - 20% tile, 20% - 30% tile, 30% - 40% tile, 40% - 50% tile,
50% - 60% tile, 60% - 70% tile, 70% - 80% tile, 80% - 90% tile, 90% - 100% tile}
(percentage of the population)

List 6 is a demonstration of the bucket test.

Casio fx-9860GII and fx-CG 50 Program PSUEDORN

"2020-02-24 EWS"
"PSUEDORANDOM INTEGERS"
"MOD(R*A+C,M)→R"
"SEED"?→S
"MULTIPLIER"?→A
"MODULUS"?→M
"INCREMENT"?→C
"SAMPLE SIZE"?→T
1 → Dim List 5
10 → Dim List 6
MOD(SA+C,M) → R
Intg(10R ÷ M)+1 → B
List 6[B] + 1 → List 6[B]
For 2 → I To T
MOD(RA+C,M) → R
Augment(List 5, {R}) → List 5
Intg(10R ÷ M) + 1 → B
List 6[B] + 1 → List 6[B]
Next
"ANALYSIS:"
"MEAN:"
Mean(List 5) ◢
List 6 ÷ Dim List 6 → List 6
"BUCKET TEST:" ◢
List 6 ◢
"RANDOM NUMBERS (List 5)" ◢
List 5

Download the fx-9860gII and fx-9750gII version: 
https://drive.google.com/open?id=1PBTzvYtwZ5wLdIJqZ-oT6obgm3HnUcCp

Download the fx-CG 50 and fx-CG 10/20 version:
https://drive.google.com/open?id=1CqHPxYMdUeJjRxV4i3lKcOtWR-X0kAGu

Example

Generate a list of psuedorandom integers from 0 to 8192 with seed 111 of sample size 25. 

r_n+1 = (3 * r_n + 4) mod (2^13 + 1)
Seed: 111

Multiplier: 3
Modulus:  2^13 + 1
Increment:  4
Sample Size:  25

Bucket Test (List 6):  { 0.2, 0.4, 0.2, 0.4, 0.4, 0, 0.2, 0.3, 0.1, 0.3 }

List (List 5):
{ 0, 1015, 3049, 958, 2878, 445, 1339, 4021, 3874, 3433, 2110, 6334, 2620, 7864, 7210, 5248, 7555, 6283, 2467, 7405, 5833, 1117, 3355, 1876, 5632 }

Eddie

All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer Welcome to a special Monday Edition of Eddie’s Math and Calculator blog. Thi...