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

Consistent RNG algorithm? #2

Closed spoike closed 6 years ago

spoike commented 6 years ago

Will this spec contain what RNG algorithm is used so it is consistent among user agents or should it be somehow configured?

E.g. if you're implementing a game that relies on the random seed should generate the same sequence of random numbers. You'd expect it to give the same sequence across the browsers (to avoid some "save-scumming" a'la XCOM, etc).

tabatkins commented 6 years ago

I'm not intending to deal with that, no. "Save-scumming" would only be possible if you switched browsers between saves. Within a single browser using the same seed will generate the same sequence.

(The main use-case I have just needs the sequence to be consistent within a single page lifetime.)

This is related to #1, where an option to choose a specific algorithm seems interesting, but can be addressed completely separately for both this and Math.random(). (Doing it for only one seems wrong.)

domenic commented 6 years ago

I think this is worth getting opinions on in committee FWIW. Is there a significant downside to picking a single specific algorithm? If not, it sure would be nice to get reliable cross-browser results.

tabatkins commented 6 years ago

No downsides, no, it's just feature creep - it's not strictly necessary for my proposal so I'm trying to avoid it for v1. Like I said, anything we do in this space should apply equally to Math.random().

domenic commented 6 years ago

I would argue that we can leave Math.random() as it is and still make the new predictable/seedable random number generator feature predictable cross-browser.

tabatkins commented 6 years ago

That seems inconsistent?

domenic commented 6 years ago

Why? Math.random() is not predictable ever, whether cross-browser or within the same browser. Whereas your API would be predictable given a seed---making it predictable cross-browser just seems natural for interop.

tabatkins commented 6 years ago

Hm, I suppose so. Okay, that does sound reasonable.

tabatkins commented 6 years ago

All right, proposal updated to specify that there will be a specific required generating algo.