PCG module

random_get_within_range

procedure · 2 overloadsSource

A float between min and max, interpolated from random_get_zero_to_one. The result is clamped into the range (so max itself can occur); equal bounds give that value.

The bounds can be given in either order: with min > max the result lies between max and min.

ExampleOpen in playground ↗
state: u64;
random_seed(*state, 7);
for 1..1000 {
    v := random_get_within_range(*state, -1.0, 2.0);
    assert(v >= -1 && v <= 2);
    w := random_get_within_range(*state, 2.0, -1.0);
    assert(w >= -1 && w <= 2);
}
assert(random_get_within_range(*state, 5.0, 5.0) == 5);
random_get_within_range :: (state: *u64, min: float, max: float) -> float

Parameters

state: *u64
min: float
max: float

Returns

float
random_get_within_range :: (min: float, max: float) -> float

Parameters

min: float
max: float

Returns

float

See also