Math,random()返回区间内的随机数
生活随笔
收集整理的這篇文章主要介紹了
Math,random()返回区间内的随机数
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
公式:
值 = Math.floor((Math.random() * 總數(shù) + 開(kāi)始值)); ? //隨機(jī)1-10隨機(jī)數(shù)
寫(xiě)成函數(shù):
function select(start,end){
var total = end - start + 1;
return Math.floor(Math.random() * total + start);
}
for (var i = 0; i < 10; i++) {
document.write(select(5,10));
document.write('</br>');
};
轉(zhuǎn)載于:https://www.cnblogs.com/zz334396884/p/6951667.html
總結(jié)
以上是生活随笔為你收集整理的Math,random()返回区间内的随机数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: github emoji 表情列表
- 下一篇: sqlite insert or rep