Home Manual Reference Source

Variable

Static Public Summary
public

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

Sample a single element from an array.

public

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

public

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

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

public

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

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

public

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

Reservoir sampling.

public

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

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

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

public

shuffled(iterable: Iterable): Array: *

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

Static Public

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

Sample a single element from an array.

Return:

any

The sampled element.

public randfloat(i: number, j: number): number: * source

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

Return:

number

A double in the interval [i, j[ taken uniformly at random.

public randint(i: number, j: number): number: * source

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

Return:

number

An integer in the interval [i, j[ taken uniformly at random.

public randrange(start: number, stop: number, step: number): number: * source

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

Return an element from range(start, stop, step) selected uniformly at random. If step is positive, this set corresponds to {x: x in [start, stop[ AND x % step = 0}. If step is negative, the range has to be given in reverse order, that is, largest value first, smallest value second. Both the starting value and the step value are optional. By default the starting value is 0. The default for the step value is 1.

TODO: Handle empty ranges.

Return:

number

The picked element.

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

Reservoir sampling.

Return:

Array

The output array.

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

Take a sample of size n (without replacement) from the items i through j-1 of the input array. This is done in-place. The sample can be retrieved from position i to i+n.

public shuffle(a: Array, i: number, j: number): * source

Shuffle array in-place between positions i and j-1 (inclusive). The other positions are left untouched.

public shuffled(iterable: Iterable): Array: * source

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

Return:

Array

The constructed array.