HP Forums

Full Version: (49G) Wichmann Hill (2005) Random Sequence Generator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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:

http://www.eurometros.org/file_download....le_key=247

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
;
Reference URL's