deepbox/random
Generation & Seeding
Seed control, Generator instances, and the core random array factories used across Deepbox.
Reproducibility
type RandomOptions
export type RandomOptions = { readonly dtype?: DType; readonly device?: Device; };
RandomOptions is a public type in deepbox/random.
Generator
Independent random state object, similar to NumPy's Generator.
setSeed
export declare function setSeed(seed: number): void;
Set global random seed.
getSeed
export declare function getSeed(): number | undefined;
Get current random seed.
clearSeed
export declare function clearSeed(): void;
Clear the current random seed and revert to cryptographically secure randomness.
rand
export declare function rand(shape: Shape, opts?: RandomOptions): Tensor;
Random values in half-open interval [0, 1).
randn
export declare function randn(shape: Shape, opts?: RandomOptions): Tensor;
Random samples from standard normal distribution.
randint
export declare function randint(low: number, high: number, shape: Shape, opts?: RandomOptions): Tensor;
randint is exported by deepbox/random.
random-generation.ts
import { Generator, getSeed, rand, randint, randn, setSeed } from "deepbox/random";setSeed(42);console.log(getSeed());console.log(rand([2, 2]).toString());console.log(randn([2, 2]).toString());console.log(randint(0, 10, [5]).toString());console.log(Array.from(new Generator(42).normalArray(0, 1, 3)));