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

Is there a polyfill ? #17

Open GrosSacASac opened 3 years ago

ljharb commented 3 years ago

I hope not; polyfills shouldn’t really exist or be used until stage 3, except as explanatory tools for the proposal itself.

cowboyd commented 2 years ago

@ljharb why not? How do you really know an API is good until you try it out?

Anyway, regardless of the API, would love to have a saveable/restorable random seed generator. If anybody knows of one out there....

ljharb commented 2 years ago

@cowboyd you can write a function that provides the same API without needing to actually polyfill anything.

cowboyd commented 2 years ago

@ljharb agreed. What I was looking for would perhaps be more accurately called a maybefill.

In any event, for those coming here, I was able to accomplish serializing and deserializing the random seed state using the alea npm package https://github.com/coverslide/node-alea

The seed function has an importState() and exportState() that lets you continue from anywhere in the sequence of pseudo random numbers.