In comp.lang.javascript message <49***********************@news.sunsite.

dk>, Sun, 2 Nov 2008 00:00:02, FAQ server <ja********@dotinternet.be>

posted:

>

// positive integer expected

function Random(j) {

return Math.floor(j * Math.random());

}

- gives an evenly distributed random integer in the range from

` 0 ` to ` x-1 ` inclusive; use ` Random(N)+1 ` for ` 1 ` to ` N `.

Definitely, x-1 should be j-1 .

That would be nicer as

function Random(j) {

return Math.floor(j * Math.random());

}

With ` j ` a positive integer, that gives an evenly distributed random

integer in the range from ` 0 ` to ` j-1 ` inclusive; use ` Random(N)+1

` for ` 1 ` to ` N `.

--

(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3

news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.

<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.

<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.