PCG module

random_get_zero_to_one

procedure · 2 overloadsSource

A float in [0, 1) made by dividing a 32-bit draw by 2^32.

A float has only 24 bits of precision, so a draw within 128 of the top would round up to 1.0; those draws give the largest float below 1 instead, so 1 never occurs.

ExampleOpen in playground ↗
state: u64;
random_seed(*state, 3);
for 1..1000 {
    r := random_get_zero_to_one(*state);
    assert(r >= 0 && r < 1);
}
random_get_zero_to_one :: (state: *u64) -> float

Parameters

state: *u64

Returns

float
random_get_zero_to_one :: () -> float

Returns

float

See also