HP Forums
(48G) 48G, 49G & 50G: Explicit Inverse Congruential Random Number 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: (48G) 48G, 49G & 50G: Explicit Inverse Congruential Random Number Generator (/thread-4409.html)



(48G) 48G, 49G & 50G: Explicit Inverse Congruential Random Number Generator - Gerald H - 07-23-2015 07:21 AM

An Explicit Inverse Coungruential Random Number Generator to base 2 ^WORDSIZE.

SDR seeds constants a & b with suitable values to ensure maximum period & the counter j with a random value.

NEXTX produces the next hexadecimal string in the sequence using the formula

next := j * ( j * a + b ) ^ -1 MODULO 2 ^ WORDSIZE

where j increases by 1 at each iteration.

NEXTR returns the next real in the sequence, next divided by the modulus.

TO USE:

Set wordsize as required, actuate SDR - NEXTX or NEXTR will then return the sequence you require.

I would be grateful for reports of (in-)adequacy of the randomness of sequences produced.
Code:

SDR

::
  CK0
  BINT3
  ZERO_DO
  BINT2
  ZERO_DO
  %RAN
  % 1.E12
  %*
  %>#
  LOOP
  bit*
  LOOP
  '
  ID j
  STO
  HXS 00001 4
  DUPUNROT
  bit/
  bit*
  HXS 00001 2
  bit+
  '
  ID a
  STO
  HXS 00001 2
  DUPUNROT
  bit/
  bit*
  HXS 00001 1
  bit+
  '
  ID b
  STO
;

NEXTX

::
  CK0
  ID j
  DUPDUP
  HXS 00001 1
  bit+
  '
  ID j
  STO
  ID a
  bit*
  ID b
  bit+
  HXS 00001 1
  SWAP
  WORDSIZE
  #1-
  ONE_DO
  DUPUNROT
  bit*
  SWAPDUP
  bit*
  LOOP
  DROP
  bit*
;

NEXTR

::
  CK0
  ID NEXTX
  HXS>%
  %2
  WORDSIZE
  FPTR2 ^RP#
  %/
;