(49G) Wichmann Hill (2005) Random Sequence Generator
07-15-2015, 03:03 PM (This post was last modified: 06-15-2017 01:42 PM by Gene.)
Post: #1
 Gerald H Senior Member Posts: 1,457 Joined: May 2014
(49G) Wichmann Hill (2005) Random Sequence Generator
Wichmann & Hill's algorithm produces a sequence of randomly distributed reals in the range zero to one.

I dispense with the traditional "pseudo" in my description as the term now merely means "algorithmically produced".

For information concerning the algorithm see:

SETWH sets the parameters s1 to s4 for no input.

NEXTR takes no input & returns the next random real to the stack.

Code:

SETWH

::
CK0
BINT5
ONE_DO
%RAN
% 2147483017.
%*
%IP
FPTR2 ^R>Z
"s"
INDEX@
#>$&$
\$>ID
STO
LOOP
;

NEXTR

::
CK0
ZINT 2147483579
ID s1
ZINT 11600
FPTR2 ^RMULText
OVER
FPTR2 ^ZMod
DUP'
ID s1
STO
FPTR2 ^Z>R
SWAP
FPTR2 ^Z>R
%/
ZINT 2147483543
ID s2
ZINT 47003
FPTR2 ^RMULText
OVER
FPTR2 ^ZMod
DUP'
ID s2
STO
FPTR2 ^Z>R
SWAP
FPTR2 ^Z>R
%/
ZINT 2147483423
ID s3
ZINT 23000
FPTR2 ^RMULText
OVER
FPTR2 ^ZMod
DUP'
ID s3
STO
FPTR2 ^Z>R
SWAP
FPTR2 ^Z>R
%/
ZINT 2147483123
ID s4
ZINT 33000
FPTR2 ^RMULText
OVER
FPTR2 ^ZMod
DUP'
ID s4
STO
FPTR2 ^Z>R
SWAP
FPTR2 ^Z>R
%/
%+
%+
%+
%FP
;
 « Next Oldest | Next Newest »

 Messages In This Thread (49G) Wichmann Hill (2005) Random Sequence Generator - Gerald H - 07-15-2015 03:03 PM

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