Home Manual Reference Source

References

api

summary
public

F random(): number

Returns a double in the interval [0, 1) using JavaScript Math.random().

public

V choice(a: Array, i: number, j: number): any: *

Sample a single element from an array.

public

V randfloat(i: number, j: number): number: *

Returns a double in interval [i, j[ (i included, j excluded) according to a uniform distribution.

public

V randint(i: number, j: number): number: *

Returns an integer in interval [i, j[ (i included, j excluded) according to a uniform distribution.

public

V randrange(start: number, stop: number, step: number): number: *

Pick an element from range(start, stop, step) uniformly at random.

public

V reservoir(k: number, iterable: Iterable, output: Array): Array: *

Reservoir sampling.

public

V sample(n: number, a: Array, i: number, j: number): *

Take a sample of size n (without replacement) from the items i through j-1 of the input array.

public

V shuffle(a: Array, i: number, j: number): *

Shuffle array in-place between positions i and j-1 (inclusive).

public

V shuffled(iterable: Iterable): Array: *

Given an input iterable, constructs an array containing the elements of the input shuffled uniformly at random.

kernel

summary
private

F _choice(randint: Function): Function

Builds a choice function given a randint function.

private

Sample elements from an array using Fisher-Yates method.

private

Shuffle elements of an iterable using an inside-out implementation of the Fisher-Yates method.

private

Builds a randfloat function given a random number generator.

private

F _randint(random: Function): Function

Builds a randint function given a random number generator.

private

Builds a randrange function given a randint function.

private

F _shuffle(sample: Function): Function

Shuffle the array by sampling the entire array.

private

F _waterman(randint: Function): Function

Construct a sampling function using Algorithm R due to Alan Waterman (both name and attribution are due to Knuth).

Directories