// alert( Math.round(3.4) );
// 0~1 : Math.round(Math.random());
// 0~10
// alert( Math.round(Math.random()*10) );
// 5~10
// alert( Math.round( Math.random()*5 + 5 ) );
// 10~20
// alert( Math.round( Math.random()*10 + 10 ) );
// 20~100
// alert( Math.round( Math.random()*80 + 20 ) );
// x ~ y
var x = 3;
var y = 49;
// alert( Math.round( Math.random()*(y-x) + x ) );
// 0~x
// alert( Math.round( Math.random()*x) );
// 1~x
alert( Math.ceil( Math.random()*x) );
转载于:https://www.cnblogs.com/TianHero/p/6050662.html