几十年前的可自定义种子的随机数生成代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<SCRIPT LANGUAGE="JavaScript"> <!-- // The Central Randomizer 1.3 (C) 1997 by Paul Houle (paul@honeylocust.com) // See: http://www.honeylocust.com/javascript/randomizer.html rnd.today=new Date(); rnd.seed=rnd.today.getTime(); function rnd() { rnd.seed = (rnd.seed*9301+49297) % 233280; return rnd.seed/(233280.0); }; function rand(number) { return Math.ceil(rnd()*number); }; // end central randomizer. --> </SCRIPT> |
参考:
The Central Randomizer
Linear congruential generator
http://www.ict.griffith.edu.au/anthony/info/C/RandomNumbers
JavaScript随机数生成算法中为什么要用9301, 49297, 233280作为Magic Number