js 返回两数(包含这两数)之间的随机数函数
function selectFrom( lowerValue, upperValue ){ var choices = upperValue - lowerValue + 1; return Math.floor( Math.random() * choices + lowerValue ); } var num = selectFrom( 2,10 ); alert( num );
function selectFrom( lowerValue, upperValue ){ var choices = upperValue - lowerValue + 1; return Math.floor( Math.random() * choices + lowerValue ); } var num = selectFrom( 2,10 ); alert( num );