js 返回两数(包含这两数)之间的随机数函数

function selectFrom( lowerValue, upperValue ){
            var choices = upperValue - lowerValue + 1;
            return Math.floor( Math.random() * choices + lowerValue );
}
var num = selectFrom( 2,10 );
alert( num );

 

posted @ 2014-01-20 16:59  sunsweet  阅读(407)  评论(0编辑  收藏  举报