random-from-seed.js 473 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. // Found this seed-based random generator somewhere
  3. // Based on The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu)
  4. var seed = 1;
  5. /**
  6. * return a random number based on a seed
  7. * @param seed
  8. * @returns {number}
  9. */
  10. function getNextValue() {
  11. seed = (seed * 9301 + 49297) % 233280;
  12. return seed/(233280.0);
  13. }
  14. function setSeed(_seed_) {
  15. seed = _seed_;
  16. }
  17. module.exports = {
  18. nextValue: getNextValue,
  19. seed: setSeed
  20. };