(27S) Linear Congruential Random Number Generator
11-22-2015, 04:12 PM (This post was last modified: 06-15-2017 01:23 PM by Gene.)
Post: #1
 Gerald H Senior Member Posts: 1,448 Joined: May 2014
(27S) Linear Congruential Random Number Generator
The next pseudorandom number R# given by the formula

R# := ( R# * A# + C# ) MOD R#MOD

is produced by the equation below, to be stored in the Solve application on the HP 27S calculator.

Store the modulus, eg

999,999,999,989

in R#MOD, multiplier, eg

979,767,979,797

1

in C# and a seed, eg

1666

in R#.

Actuating R# will produce the next pseudorandom integer, in our case

293,454,359,755.

The variable FRCT seen in the variable menu is only to be recalled, not actuated, & shows the value of R# / R#MOD.

Results are correct for R#MOD < 10^12.

Code:
 R#=0*AR#*CR#+L(R,MOD(MOD(MOD(MOD(MOD(L(X,G(R#)-L(I,MOD(G(R#),1000000)))*L(H,G(AR#)-L(J,MOD(G(AR#),1000000))),R#MOD)+MOD(G(X)*G(J),-R#MOD),R#MOD)+MOD(G(H)*G(I),-R#MOD),-R#MOD)+G(I)*G(J),-R#MOD)+CR#,R#MOD))+0*L(FRCT,G(R)/R#MOD)*FRCT
 « Next Oldest | Next Newest »

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