You are here: irt.org | FAQ | JavaScript | Random | Q598 [ previous next ]
Use the Central Randomizer script:
<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 between 0 and 25, use:
rand(26)-1;
For information about random numbers take a look at Random Numbers & Random Events