HP Forums
(38G) Lagged Fibonacci PRNG - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (38G) Lagged Fibonacci PRNG (/thread-4445.html)



(38G) Lagged Fibonacci PRNG - Gerald H - 07-28-2015 09:45 AM

For info on theory see:

https://en.wikipedia.org/wiki/Lagged_Fibonacci_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: