A float between min and max, both ends possible, computed as min + (max - min) * r and clamped back into the range if rounding strays.
The bounds can be given in either order: with min > max the result lies between max and min. Equal bounds give that value. The draw has 24 bits of resolution, so the result takes at most 2^24 distinct values across the range.
state: Random_State;
random_seed(*state, cast(u64) 5);
for 1..1000 {
v := random_get_within_range(*state, -2.0, 3.0);
assert(v >= -2 && v <= 3);
}
assert(random_get_within_range(*state, 4.0, 4.0) == 4);
w := random_get_within_range(*state, 3.0, -2.0);
assert(w >= -2 && w <= 3);random_get_within_range :: (
state: *Random_State,
min: float,
max: float
) -> float
A float between min and max.
Parameters
- state: *Random_State
- min: float
- one end of the range. The ends may be given in either order.
- max: float
- the other end.
Returns
- float
random_get_within_range :: (min: float, max: float) -> float
Parameters
- min: float
- max: float
Returns
- float