js返回两个数之间的随机数

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-23 15:36   11   0
//方法一:
function rd(n,m){  
    var c = m-n+1;    
    return Math.floor(Math.random() * c + n);  
}  
 
//方法二:
function selectfrom (lowValue,highValue){ var choice=highValue-lowValue+1; return Math.floor(Math.random()*choice+lowValue); }


//方法三:
function randomNum(num1,num2){
    return Math.random()*(num2-num1)+num1  
}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP