Initialize the default PCG sequence from a seed.
Random
Pure pseudorandom generators supplied by
kili-ilo/roc-random.
Seed a State once during init!, retain it in the model, and pass the
returned state into the next draw. Keeping simulation randomness in model
state makes draws immediate during update! and reproduces a run from its
initial seed.
generation = Random.step(model.rng, Random.bounded_i32(0, 799))
Ok({ ..model, rng: generation.state, x: generation.value })
App.entropy! is the one thing that makes a run differ from the last one:
seed from it for a run that should vary, and from a constant for one that
must reproduce.
This module is a platform-facing facade only. State, Generator and
Generation are the package's own types, re-exported here, and the PCG
implementation, the unbiased bounded generators, and the combinators all
live in the external package.
seed_variant : U32, U32 -> State
Initialize an independent PCG sequence from a seed and sequence ID.
step : State, Generator(value) -> Generation(value)
Run a generator from a state.
next : Generation(_), Generator(value) -> Generation(value)
Run another generator from a previous generation's output state.
static : value -> Generator(value)
Construct a generator that always returns value without advancing.
map : Generator(a), (a -> b) -> Generator(b)
Transform the output of a generator.
map2 : Generator(a), Generator(b), (a, b -> c) -> Generator(c)
Combine two generators in sequence.
chain : Generator(a), (a -> Generator(b)) -> Generator(b)
Choose a subsequent generator from the output of the first.
Generate a list of length values.
Generate a shuffled copy of a list.
Generate either Boolean value with equal probability.
Generate a U8 across the type's full range.
Generate an I8 across the type's full range.
Generate a U16 across the type's full range.
Generate an I16 across the type's full range.
Generate a U32 across the type's full range.
Generate an I32 across the type's full range.
Generate a U64 across the type's full range.
Generate an I64 across the type's full range.
bounded_u8 : U8, U8 -> Generator(U8)
Generate a U8 between two inclusive bounds, without modulo bias.
bounded_i8 : I8, I8 -> Generator(I8)
Generate an I8 between two inclusive bounds, without modulo bias.
bounded_u16 : U16, U16 -> Generator(U16)
Generate a U16 between two inclusive bounds, without modulo bias.
bounded_i16 : I16, I16 -> Generator(I16)
Generate an I16 between two inclusive bounds, without modulo bias.
bounded_u32 : U32, U32 -> Generator(U32)
Generate a U32 between two inclusive bounds, without modulo bias.
bounded_i32 : I32, I32 -> Generator(I32)
Generate an I32 between two inclusive bounds, without modulo bias.
bounded_u64 : U64, U64 -> Generator(U64)
Generate a U64 between two inclusive bounds, without modulo bias.
bounded_i64 : I64, I64 -> Generator(I64)
Generate an I64 between two inclusive bounds, without modulo bias.
Generate an F32 in [low, high).
Generate an F64 in [low, high).
Choose between the required first value and any following choices.
choice_try : List(a) -> Try(Generator(a), [ListWasEmpty])
Choose an item from a nonempty list, or report ListWasEmpty.
choice_weighted : (a, F64), List((a, F64)) -> Generator(a)
Choose between weighted values. Weights must be finite and nonnegative.
choice_weighted_try : List((a, F64)) -> Try(Generator(a), [ListWasEmpty])
Choose from a weighted list, or report ListWasEmpty.
State : State
State threaded through successive pseudorandom generations. This is
roc-random's own State, re-exported.
Generator : Generator(value)
A pure generator that transforms a state into a value and its next state.
This is roc-random's own Generator, re-exported.
Generation : Generation(value)
A generated value paired with the state for the next draw. This is
roc-random's own Generation, re-exported.