Module: math.random

Source: ./math/random.reef


Overview

math/random - Random number generation

Provides functions for generating pseudo-random numbers. Uses Xorshift32 algorithm - a fast, pure Reef PRNG implementation. Period: 2^32-1 (approximately 4 billion values before repeating)


Functions

fn xorshift32(): int

fn random_int(): int

Returns a random non-negative integer

fn random_int_max(max: int): int

Returns a random integer in range [0, max) max must be positive

fn random_int_range(min_val: int, max_val: int): int

Returns a random integer in range [min_val, max_val]

fn random_float(): float

Returns a random float in range [0.0, 1.0)

fn random_float_range(min_val: float, max_val: float): float

Returns a random float in range [min_val, max_val)

fn random_bool(): bool

Returns a random boolean (true or false with equal probability)


Procedures

proc seed(s: int)

Seeds the random number generator with a specific value Use for reproducible sequences Note: seed must be non-zero for Xorshift to work properly

proc seed_time()

Seeds the random number generator with current time Use for unpredictable sequences


Generated by reefc doc