API reference
Random state
| Name | Summary |
|---|---|
np.get_state | Return the internal state of the global RandomState as a bigint array (MT19937 words). |
np.set_state | Restore the global RandomState from a bigint array returned by get_state. |
np.ranf | Return random floats in [0.0, 1.0). |
np.sample | Alias for np.random.random. |
np.random_integers | Return 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
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
const state = np.random.get_state();
np.random.set_state(state);
typeof state; // => "object"TypeScript declaration
np.random.set_state(words: bigint[]): voidnp.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
np.random.ranf([3]).shape; // => [3]TypeScript declaration
np.random.ranf(size?: Size | null | undefined): number | boolean | NDArray | Complexnp.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
np.random.sample([2, 3]).shape; // => [2, 3]TypeScript declaration
np.random.sample(size?: Size | null | undefined): number | boolean | NDArray | Complexnp.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
np.random.random_integers(5).valueOf() <= 5; // => trueTypeScript declaration
np.random.random_integers(low: number, high?: number | null | undefined, size?: Size | null | undefined): number | boolean | NDArray | Complex