You are here: irt.org | FAQ | JavaScript | Random | Q343 [ previous next ]
The Central Randomizer has an excellent random number generator for public domain use (as long as it remains unchanged):
<SCRIPT> <!-- // The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu) // See: http://www.msc.cornell.edu/~houle/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>
To use the Central Randomizer code, ensure it is placed between the <HEAD> and </HEAD> HTML tags.
To create a random floating point number use: rnd(), to create a random integer, say between 1 and 10, use rand(10).