HP Forums

Full Version: (38G) Lagged Fibonacci PRNG
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
For info on theory see:

https://en.wikipedia.org/wiki/Lagged_Fib..._generator

LFibSeeder seeds a vector of 127 random integers from 0 to M-1, M a positive integer given as input from Ans in the HOME screen.

Code:

LFibSeeder

Ans►M:
MAKEMAT(INT(RANDOM*M),127,1)*[1]►M1:

LFibNext adds the 30th & 127th elements of the vector MODULO M, stores this value as the new first element of the vector, deletes the 128th element of the vector & returns new first element divided by M to Ans in the HOME screen.

Code:

LFibNext

ADDCOL M1;((M1(127) MOD -M)+M1(30)) MOD M;1:
DELCOL M1;128:
M1(1)/M:
Reference URL's