random icon indicating copy to clipboard operation
random copied to clipboard

Provide access to construct a generator from `Seed -> (a, Seed)`

Open z5h opened this issue 1 year ago • 0 comments

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.

z5h avatar Sep 20 '23 01:09 z5h