05-09-2008

Javascript Generating random integer with Math.random()

where 11 dictates that the random number will fall between 0-10. To increase the range to, say, 100, simply change 11 to 101 instead.

var randomnumber=Math.floor(Math.random()*11)

To generate a random number within a range between two whole numbers you can use the following code:

function randomnumber(start,end){
	return Math.floor(Math.random() * (end - start + 1) + start);
}

Comments:

Your comment:

»

 

[x]