// 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) );

posted on 2016-11-10 13:54  良小辰  阅读(227)  评论(0编辑  收藏  举报