Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
z5h opened this issue Sep 20, 2023 · 0 comments
Open

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

z5h opened this issue Sep 20, 2023 · 0 comments

Comments

@z5h
Copy link

z5h commented Sep 20, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant