Random Generators

These are methods of generating a sample, x, for a given random variable, X.

No guarantees are made as to the distribution of the random variable.

Float

X := [ 0, 1 )

() => Math.random(); // R

X := ( 0, 1 ]

() => -(Math.random() - 1); // -(R-1)

X := [ 0, N )

(N) => Math.random() * N; // R*N

X := [ M, N )

(M, N) => Math.random() * (N - M) + M; // R*(N-M)+M

X := [ 1, Infinity )

() => -1 / (Math.random() - 1); // -1/(R-1)

X := ( 1, Infinity ]

() => Math.random() ** (-1 / Math.random()); // R^(-1/R)

Integer

X := [ 1, N ]

(N) => Math.ceil(Math.random() * N); // ⌈R*N⌉

X := [ 0, N ]

(N) => Math.floor(Math.random() * N + 1); // ⌊R*N+1⌋

X := [ M, N ]

(M, N) => Math.floor(Math.random() * (N - M + 1) + M); // ⌊R*(N-M)+N⌋

Boolean

X := { true, false }

() => Math.random() < 0.5; // R<0.5

Multiset (Array)

X := []:Array< any >

(...A) => A[Math.floor(Math.random() * A.length)]; // A[⌊R*|A|⌋]

Bytes

X := TypedArray< number >(N)

(N) => globalThis.crypto.getRandomValues(new Uint8ClampedArray(N)); // g(N)