Cyforanumera
npm

API reference

Random state

NameSummary
np.get_stateReturn the internal state of the global RandomState as a bigint array (MT19937 words).
np.set_stateRestore the global RandomState from a bigint array returned by get_state.
np.ranfReturn random floats in [0.0, 1.0).
np.sampleAlias for np.random.random.
np.random_integersReturn random integers from low (inclusive) to high (inclusive).

np.get_state

#
np.random.get_state()

Return the internal state of the global RandomState as a bigint array (MT19937 words). Can be restored with set_state. Equivalent to numpy.random.get_state.

Returns

bigint[]

Example

TypeScript
const state = np.random.get_state();
typeof state; // => "object"
TypeScript declaration
np.random.get_state(): bigint[]

np.set_state

#
np.random.set_state(words)

Restore the global RandomState from a bigint array returned by get_state. Equivalent to numpy.random.set_state.

Parameters

wordsbigint[]
State words from get_state().

Returns

void

Example

TypeScript
const state = np.random.get_state();
np.random.set_state(state);
typeof state; // => "object"
TypeScript declaration
np.random.set_state(words: bigint[]): void

np.ranf

#
np.random.ranf(size?)

Return random floats in [0.0, 1.0). Alias for np.random.random. Equivalent to numpy.random.ranf.

Parameters

[size]number | number[]
Output shape.

Returns

NDArray | number

Example

TypeScript
np.random.ranf([3]).shape; // => [3]
TypeScript declaration
np.random.ranf(size?: Size | null | undefined): number | boolean | NDArray | Complex

np.sample

#
np.random.sample(size?)

Alias for np.random.random. Return random floats in [0.0, 1.0). Equivalent to numpy.random.sample.

Parameters

[size]number | number[]
Output shape.

Returns

NDArray | number

Example

TypeScript
np.random.sample([2, 3]).shape; // => [2, 3]
TypeScript declaration
np.random.sample(size?: Size | null | undefined): number | boolean | NDArray | Complex

np.random_integers

#
np.random.random_integers(low, high?, size?)

Return random integers from low (inclusive) to high (inclusive). If high is null, returns integers in [1, low]. Deprecated in NumPy — use randint instead. Equivalent to numpy.random.random_integers.

Parameters

lownumber
Lowest integer (or highest if high omitted).
[high]number | null
Highest integer (inclusive).
[size]number | number[]
Output shape.

Returns

NDArray | number

Example

TypeScript
np.random.random_integers(5).valueOf() <= 5; // => true
TypeScript declaration
np.random.random_integers(low: number, high?: number | null | undefined, size?: Size | null | undefined): number | boolean | NDArray | Complex