random
random copied to clipboard
Provide access to construct a generator from `Seed -> (a, Seed)`
In Random we have:
type Generator a =
Generator (Seed -> (a, Seed))
So if I have a way of doing Seed -> (a, Seed))
, I should be able to make a Generator a
.
Well not exactly.
I can do:
fromStep : (Seed -> ( a, Seed )) -> Generator a
fromStep step =
Random.independentSeed |> Random.map (step >> Tuple.first)
The problem here is independantSeed
goes through the extra work of creating a new seed, and then we throw out the seed after the generator is used.
There’s no way to use a seed and step, (generating a value) and returning the value and the next seed.