Closed TimothyGu closed 3 years ago
Hahaha, I literally just changed away from a generator-based design.
I think that the current design makes more sense overall.
Math.random()
and prng.random()
is very nice.prng.next().value
. (Basically, a sequence of random numbers is typically treated differently from other infinite iterators; it's pulled as needed, not until the value hits some condition.)function* rand(...args) { const prng = Math.seededPRNG(...args); while(1) yield prng.random(); }
. Doing the reverse, while not hard, is less trivial.I encourage you to actually go thru some code examples that currently use Math.random() and see how they look with prng.random()
vs an iterator.
As an aside, I consider the .next()
method of generators to be, most of the time, an implementation detail, not an affirmatively-exposed part of your API. You rarely call next()
directly in Python, for example. The {next,done} return value is inconvenient and weird to work with directly.
Closing, as I think copying the stateful design of Math.random()
is definitely still the right way to go here, for the reasons listed above.
It would seem to be nice for
Math.seededPRNG()
to return an iterator, so instead of.random()
the user would instead call the more standard.next()
. It would also be easier to reason aboutMath.seededPRNG()
as a generator function.