random_alea.ts

Alea: a seedable pseudo-random number generator by Johannes Baagøe. Supports variadic and string seeds (create_random_alea('my', 3, 'seeds')). For numeric seeds, prefer create_random_xoshiro which is faster with equal quality.

DO NOT USE when security matters — use the Web Crypto API (crypto.getRandomValues) instead.

Alea passes all 11 distribution quality tests at 10M samples, performing on par with Math.random (V8's xorshift128+):

  • mean, variance, chi-squared uniformity, Kolmogorov-Smirnov
  • lag-1 through lag-8 autocorrelation
  • runs test, gap test, permutation test (triples)
  • bit-level frequency (bits 0-7)
  • 2D serial pairs (25x25 through 200x200 grids)
  • birthday spacings (Marsaglia parameters)

Speed is ~19% slower than Math.random (~12.2M ops/sec vs ~15.0M ops/sec).

To reproduce:

npm run benchmark_random_quality # distribution tests (N=1M) npm run benchmark_random_quality -- --deep # thorough (N=10M, multi-trial) npm run benchmark_random # speed comparison

@see https://github.com/nquinlan/better-random-numbers-for-javascript-mirror

view source

Declarations
#

2 declarations

create_random_alea
#

RandomAlea
#

random_alea.ts view source

RandomAlea import type {RandomAlea} from '@fuzdev/fuz_util/random_alea.js';

uint32

type () => number

fract53

type () => number

version

type string

seeds

type Array<unknown>

(call)

type (): number

returns number