Pseudo random number generators

From ScienceZero
Jump to: navigation, search

The algorithms described here are designed for maximum efficiency and are not meant to be cryptographically secure or suited for general scientific use. In some cases they have better properties than some old and very slow algorithms. Some linear feedback shift registers are excellent pseudo random number generators.

ARM

The ARM instruction set makes it simple to make short generators of high quality.

Shortest possible

A single instruction generator, it was selected after testing all possible instructions of a suitable type:

RSB R0,R0,R0,ROR #21

Use the seed 0xFB000 for a period of 1 703 271.

The analysis of 40 000 000 bytes worth of the least significant byte:

  • Entropy = 7.999 985 bits per byte.
  • Optimum compression would reduce the size of this 40 000 000 byte file by 0 percent.
  • Chi square distribution for 40 000 000 samples is 810.80, and randomly would exceed this value 0.01 percent of the times.
  • Arithmetic mean value of data bytes is 127.4731 (127.5 = random).
  • Monte Carlo value for Pi is 3.143 189 714 (error 0.05 percent).
  • Serial correlation coefficient is -0.000 131 (totally uncorrelated = 0.0).

High quality, long period

EOR R0,R0,R1
ADD R1,R1,R0,ROR #16

PIC

The PIC has a limited instruction set and develop platform that makes it difficult to develop good generators.

High quality, long period

This is the same as the ARM one but using two 8 bit variables instead of two 32 bit variables.

MOVFW R1
XORWF R0
SWAPF R0,W
ADDWF R1