From: FAQ server on
-----------------------------------------------------------------------
FAQ Topic - How do I generate a random integer from 1 to
n?
-----------------------------------------------------------------------

` Math.random() ` returns a value ` R ` such that ` 0 <= R < 1.0 `; therefore:

// positive integer expected
function getRandomNumber(n) {
return Math.floor(n * Math.random());
}

- gives an evenly distributed random integer in the range from
` 0 ` to ` n - 1 ` inclusive; use ` getRandomNumber(n)+1 ` for ` 1 ` to ` n `.

http://msdn.microsoft.com/en-us/library/41336409%28VS.85%29.aspx

http://docs.sun.com/source/816-6408-10/math.htm

How to Deal and Shuffle, see in:

http://www.merlyn.demon.co.uk/js-randm.htm


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.