課程
/前端開(kāi)發(fā)
/JavaScript
/JavaScript進(jìn)階篇
究竟是Math.round(Math.random()*10)還是Math.round((Math.random())*10)?有區(qū)別嗎?
2018-09-10
源自:JavaScript進(jìn)階篇 7-16
正在回答
沒(méi)區(qū)別,Math.random()*10和(Math.random())*10?? 相當(dāng)于a*b和(a)*b
兩者是有區(qū)別的:
????Math.round(Math.random())*10;
????這種情況下得到的值只有10或0,因?yàn)槭?~1的隨機(jī)數(shù)近似只有0和1兩種情況。
????Math.round(Math.random()*10);
????這種情況下隨機(jī)數(shù)取到的值再*10便在0~10之間了,然后便是四舍五入取整。
麻辣燙不加辣
有區(qū)別的呀,結(jié)果肯定不一樣
舉報(bào)
本課程從如何插入JS代碼開(kāi)始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
4 回答document.write(Math.round((Math.random())*10));
3 回答document.write(Math.round((Math.random())*10))得到的不是整數(shù)
5 回答Math.random和Math.round的輸出值不對(duì)是什么原因?
2 回答Math.round()中
1 回答這個(gè)任務(wù)就很奇怪 隨機(jī)值*10 使用Math.round 萬(wàn)一等到的值是 9.51呢
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-09-10
沒(méi)區(qū)別,Math.random()*10和(Math.random())*10?? 相當(dāng)于a*b和(a)*b
2018-11-24
兩者是有區(qū)別的:
????Math.round(Math.random())*10;
????這種情況下得到的值只有10或0,因?yàn)槭?~1的隨機(jī)數(shù)近似只有0和1兩種情況。
????Math.round(Math.random()*10);
????這種情況下隨機(jī)數(shù)取到的值再*10便在0~10之間了,然后便是四舍五入取整。
2018-11-13
有區(qū)別的呀,結(jié)果肯定不一樣