ckknight / random-js

A mathematically correct random number generator library for JavaScript.
MIT License
603 stars 49 forks source link

Serialize and unserialize for later use #25

Closed Darkhogg closed 6 years ago

Darkhogg commented 6 years ago

Is there a way of storing the current state of the generator in a way that can be restored later? If not, can it be done?

Darkhogg commented 6 years ago

I've been looking into it and I'm going to reply to myself:

No, there is no way to serialize a generator, but Yes, it can technically be done (for mt19937 at least): It's enough to store the seed used and a count of values (getUsedCount()) so that you can seed().discard() later and resume the random in the same position.

I'm closing this issue as that's enough for me.