HP Forums
(49G) Wichmann Hill (2005) Random Sequence Generator - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (49G) Wichmann Hill (2005) Random Sequence Generator (/thread-4365.html)



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

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.php?file_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
;