The std.random
module provides a comprehensive set of functions for random number generation, including basic random numbers, range-based selections, and various probability distributions.
Sets the seed for the random number generator to produce reproducible sequences of random numbers.
Parameters:
value
: An integer value to use as the seedExample:
Generates a random floating-point number between 0.0 (inclusive) and 1.0 (exclusive).
Returns:
Example:
Generates a random integer between min and max (inclusive).
Parameters:
min
: The lower bound (inclusive)max
: The upper bound (inclusive)Returns:
Example:
Generates a random floating-point number from a uniform distribution between min and max.
Parameters:
min
: The lower bound (inclusive)max
: The upper bound (exclusive)Returns:
Example:
Generates a random integer from a range with optional step size.
Parameters:
start
: The start of the range (inclusive)end
: The end of the range (exclusive)step
: (Optional) The step size between numbersReturns:
Example:
Randomly selects an element from a list.
Parameters:
list
: An array of elements to choose fromReturns:
Example:
Generates a random floating-point number from a normal (Gaussian) distribution.
Parameters:
mean
: The mean (average) of the distributionstd_dev
: The standard deviation of the distributionReturns:
Example:
Generates a random floating-point number from an exponential distribution.
Parameters:
lambda
: The rate parameter (λ) of the exponential distributionReturns:
Example:
Generates a random boolean value.
Returns:
Example: