random_xoshiro.ts

Xoshiro128**: a seedable pseudo-random number generator by Blackman & Vigna (2018). Recommended for reproducible randomness (testing, simulations, procedural generation).

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

Xoshiro128** has a 2^128-1 period and passes BigCrush. It uses pure 32-bit arithmetic (shifts, rotates, XOR, multiply) making it very fast in JavaScript via Math.imul.

Xoshiro128** 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 near-native (~4% slower than Math.random) and ~18% faster than Alea (~14.4M ops/sec vs ~15.0M and ~12.2M respectively).

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://prng.di.unimi.it/ @see https://vigna.di.unimi.it/ftp/papers/ScrambledLinear.pdf

view source

Declarations
#

2 declarations

create_random_xoshiro
#

random_xoshiro.ts view source

(seed?: number | undefined): RandomXoshiro import {create_random_xoshiro} from '@fuzdev/fuz_util/random_xoshiro.js';

Seeded pseudo-random number generator using the Xoshiro128** algorithm. DO NOT USE when security matters, use webcrypto APIs instead.

seed?

type number | undefined
optional

returns

RandomXoshiro

see also

RandomXoshiro
#

random_xoshiro.ts view source

RandomXoshiro import type {RandomXoshiro} from '@fuzdev/fuz_util/random_xoshiro.js';

uint32

type () => number

fract53

type () => number

version

type string

seed

type number

(call)

type (): number

returns number