公式:
Math.floor(Math.random()*(max-min+1)+min);
// max:最大值 min:最小值
//注:如果不包含最大值无需+1
如[5,23)即5到23且不包括23的整数
var ran = Math.floor(Math.random()*(23-5)+5);
公式:
Math.floor(Math.random()*(max-min+1)+min);
// max:最大值 min:最小值
//注:如果不包含最大值无需+1
如[5,23)即5到23且不包括23的整数
var ran = Math.floor(Math.random()*(23-5)+5);
本文标题:JS Math.random()方法取得指定范围内的随机数
本文链接:https://www.haomeiwen.com/subject/fxkmyqtx.html
网友评论