Javascript Math rand(min, max)
Math.rand = function(min, max) { if (!max) {//from w ww .j a v a 2 s .c om max = min; min = 0; } return (Math.round(Math.random() * (max - min) + min)); };