1 function selectNum(lowNum,upNum) { 2 var num = upNum-lowNum+1; 3 // Math.floor() 向下取整 4 return Math.floor(Math.random()*num+lowNum); 5 6 } 7 8 var result = selectNum(2,8); //2~8范围内的整数
时间: 2024-10-29 15:32:17
1 function selectNum(lowNum,upNum) { 2 var num = upNum-lowNum+1; 3 // Math.floor() 向下取整 4 return Math.floor(Math.random()*num+lowNum); 5 6 } 7 8 var result = selectNum(2,8); //2~8范围内的整数