davidbau/seedrandom — pull request #12 by davidbau (2014-12-11 06:54:44+00:00)
Title: Add support for saving and restoring state.

This change adds support for a prng.state() method that exposes a copy of the current internal state as a plan object that can be serialized as JSON (as requested by #11 ). A replica prng can be created later by using the option {state:obj}.

The prng.state() method is only present if the prng is created with the option {state:...} (for example {state:true} in the initial case when not loading state). That means that, by default, the prng remains bare and not easily hackable by a coder that has access to the prng function. The default mode is suitable, for example, for providing a reproducible but unpredictable PRNG function to be used in a coding contest.

This change increases the size of seedrandom.min.js by 140 bytes, from 1369 bytes to 1509 bytes (10%).