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`.

<URL: http://msdn.microsoft.com/en-us/library/41336409%28VS.85%29.aspx>
<URL: http://docs.sun.com/source/816-6408-10/math.htm>
How to Deal and Shuffle, see in: <URL: 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.

From: Dr J R Stockton on
In comp.lang.javascript message <4c54aafa$0$277$14726298(a)news.sunsite.dk
>, Sat, 31 Jul 2010 23:00:03, FAQ server <javascript(a)dotinternet.be>
posted:

>FAQ Topic - How do I generate a random integer from 1 to
>n?

>How to Deal and Shuffle, see in: <URL: http://www.merlyn.demon.co.uk/js
>-randm.htm>

Should be

To Shuffle, Deal, or Draw, see via:
<URL: http://www.merlyn.demon.co.uk/js-randm.htm>.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.