davidbau / seedrandom

seeded random number generator for Javascript
2.04k stars 160 forks source link

Add support for saving and restoring state. #12

Closed davidbau closed 9 years ago

davidbau commented 9 years ago

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%).

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-10.44%) when pulling 945862d1afd2ebbf630a1fcd4f412789db53fe4a on savestate into ecfda93d5e6694726ee9d2acfe9df6cd20381cbd on master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-10.44%) when pulling 9fa6360075eba4e91286ed55dea1e9bf56579b07 on savestate into ecfda93d5e6694726ee9d2acfe9df6cd20381cbd on master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-10.44%) when pulling 80d4b49aecdf79adcd14fccab4cd5ac7eb82ea2a on savestate into ecfda93d5e6694726ee9d2acfe9df6cd20381cbd on master.

coveralls commented 9 years ago

Coverage Status

Coverage increased (+0.67%) when pulling f71d8b922cea1346e56e1c953cfdc07babccc702 on savestate into ecfda93d5e6694726ee9d2acfe9df6cd20381cbd on master.

coveralls commented 9 years ago

Coverage Status

Coverage increased (+0.67%) when pulling d2a310b0f54c1d1c6b26421aa2b4756f91523e96 on savestate into ecfda93d5e6694726ee9d2acfe9df6cd20381cbd on master.

coveralls commented 9 years ago

Coverage Status

Coverage increased (+0.55%) when pulling df06b8bdd0b92753446968f6efc193d7a1d4f9fc on savestate into ecfda93d5e6694726ee9d2acfe9df6cd20381cbd on master.