Post Reply 
(48G) 48G, 49G & 50G: Explicit Inverse Congruential Random Number Generator
07-23-2015, 07:21 AM (This post was last modified: 06-15-2017 01:51 PM by Gene.)
Post: #1
(48G) 48G, 49G & 50G: Explicit Inverse Congruential Random Number Generator
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#
  %/
;
Find all posts by this user
Quote this message in a reply
Post Reply 




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