v2026.6.1
All Bundles
Bundle Core machine learning types: the seedable Random generator, Matrix2D linear algebra and activations, matrix reference holders, the NeuralNetwork and CSV-backed MatrixReader. Compile with -lib ml.

Random

Deterministic, seedable pseudo-random number generator (MINSTD linear congruential generator). Use this instead of `Float->Random()` when you need reproducible results -- k-means++ seeding, shuffling, and unit tests.

Example

rand := System.ML.Random->New(42);
rand->NextInt(6)->PrintLine();   # reproducible dice roll in [0, 6)
rand->NextReal()->PrintLine();   # value in (0.0, 1.0)

Operations

New # constructor

Creates a seeded generator

New(seed:Int)

Parameters

NameTypeDescription
seedIntinitial seed (values <= 0 are normalized to a valid state)

NextInt #

Advances the generator and returns the next raw integer in [1, 2147483646]

method : public : NextInt() ~ Int

Return

TypeDescription
Intpseudo-random integer

NextInt #

Returns a non-negative integer less than bound

method : public : NextInt(bound:Int) ~ Int

Parameters

NameTypeDescription
boundIntexclusive upper bound (must be > 0)

Return

TypeDescription
Intvalue in [0, bound)

NextReal #

Returns a real in the open interval (0.0, 1.0)

method : public : NextReal() ~ Float

Return

TypeDescription
Floatpseudo-random real

NextReal #

Returns a real in the half-open interval [min, max)

method : public : NextReal(min:Float, max:Float) ~ Float

Parameters

NameTypeDescription
minFloatlower bound
maxFloatupper bound (exclusive)

Return

TypeDescription
Floatpseudo-random real in range