Random Number Generation

RNG notes tech

Some info dump while I try to figure out random number generations. No TOC for this page, but here is a tree -L1

.
├── Algorithms
│   ├── CSPRNG.md
│   └── Random Tree - Linear Congruential Algo.md
└── Random Number Generation.md

2 directories, 3 files



Citations for this chunk

- Handling generators based on linear congruential algorithm with random tree method

Random Tree Method

it employs two linear congruential generators L and R that differ in a value for a

Lk+1=aLLk mod mRk+1=aRLk mod m


This is inline x2

Linear Congruential Generator generates a sequence of pseudo-random numbers using discontinuous piecewise linear equation The generator: Xn+1=(aXn+c) mod m where

func linearCongruentialGenerator(X0, m, a, c, N int) []int {
    randNums := make([]int, N)
    randNums[0] = X0
    for i := 1; i < N; i++ {
        randNums[i] = (a * randNums[i - 1] + c) % m
    }
    return randNums
}

In this case, the left generator L with a seed L0 has one random sequence. The right generator R with the same seed generates another sequence. We use the right generator for values in computation while the left generator is applied to the values computed by R to obtain the starting points for R0,R1,

When a new task is in need for random numbers, the parent generator in this case L creates a new random number in its sequence, which is then used to create a branch using the right generator R whose value is used for computation

Random Tree

When two starting points created between two consecutive values generated by L are close, the two right sequence branches will be highly correlated

Leapfrog Method

This is a variant of random tree method which can be guaranteed not to overlap over a certain period. If n is a sequence required. We define aL and aR as a and an such that we have

Lk+1=aLk mod mRk+1=anRk mod m

We create n different right generators R0Rn1 from the first n elements of the L generator. The sequence generated by Ri consists of Li and the subsequent elements of the sequence.

The sequence generated by L is portioned each having a period of Pn where P is the period of L. Hence each right generator selects a a disjoint sequence from the left generated sequence

For the rth sub-sequence, Rr is given with an and starting point from the L sequence as R0r=Lr. We need to compute ar and an

a2k mod m=(ak mod m)2 mod m

The sequence generated by Rr is defined as


R0r=(arL0) mod mRi+1r=(anRir) mod m

This method can be called recursively. The subsequence corresponding to (R0r,an,m) can be further sub-divided by a second application of leap frog, with a outcome of the subsequence becoming shorter

Modified Leapfrog

When we know the max number n of random variables needed in a sub-sequence but we don't know how many subsequences are required

Here Lin,L(i+1)(n1) are contiguous elements. Choosing n as a power of two can lead to long correlations.


Lk+1=anLk mod mRk+1=aRk mod m