tc39 / proposal-seeded-random

Proposal for an options argument to be added to JS's Math.random() function, and some options to start it with.
MIT License
156 stars 6 forks source link

Separate the concept of getting values from getting seed #4

Closed tabatkins closed 6 years ago

tabatkins commented 6 years ago

Per Waldemar and others, it's not a good idea to treat the produced value as being the next state/seed; in crypto-secure generators, in particular, the state might be a completely different structure.

Suggestion, per @domenic, is to expose a .seed() on the generator that returns the seed.

Luckily, this resolves the issue in the README about what the output space is; we can go ahead and match Math.random() and just output a value in [0,1].

@erights emphasizes that it should be possible to hide the seed-exposing functionality from down-level code. Is it okay to just require that you launder this thru a separate generator? That is:

function* iter(possibleIter) { yield* iter; }

const noVisibleState = iter(Math.seededRandom(0));

Is this okay?

tabatkins commented 6 years ago

Done.