Skip to content

Rand

Spice
import "std/math/rand";

Functions

seed

Spice
public p seed(unsigned long seedValue)

Seed the pseudo-random number generator. Note: A seed of 0 is replaced by a fixed non-zero constant, as the generator cannot escape the all-zero state.

Parameters

Name Type Description
seedValue unsigned long Seed value

randULong

Spice
public f<unsigned long> randULong()

Generate a raw pseudo-random unsigned long, uniformly distributed over the whole 64-bit range.

Returns: unsigned long — Random unsigned long

randInt

Spice
public f<int> randInt(int min, int max)

Generates a random integer between min and max Note: Both min and max are inclusive: [min, max] Note: If min > max, the function always returns max

Parameters

Name Type Description
min int
max int

Returns: int — Random number

randDouble

Spice
public f<double> randDouble()

Generate a random double, uniformly distributed in the half-open interval [0, 1).

Returns: double — Random double in [0, 1)

randDouble

Spice
public f<double> randDouble(double min, double max)

Generate a random double, uniformly distributed in the half-open interval [min, max). Note: If min > max, the function always returns max

Parameters

Name Type Description
min double Lower bound (inclusive)
max double Upper bound (exclusive)

Returns: double — Random double in [min, max)

randBool

Spice
public f<bool> randBool()

Generate a random boolean value with equal probability for true and false.

Returns: bool — Random boolean

randGaussian

Spice
public f<double> randGaussian(double mean, double stdDev)

Generate a normally distributed random double with the given mean and standard deviation, using the Box-Muller transform.

Parameters

Name Type Description
mean double Mean of the distribution
stdDev double Standard deviation of the distribution

Returns: double — Normally distributed random double