課程
/前端開發(fā)
/JavaScript
/JavaScript進(jìn)階篇
如何用random()產(chǎn)生0-9的隨機(jī)數(shù)? 即0≤隨機(jī)數(shù)≤9
2019-02-23
源自:JavaScript進(jìn)階篇 7-16
正在回答
<script type="text/javascript">
document.write(Math.round(Math.random()));
</script>
var num=Math.floor(Math.random()*10);因?yàn)閞andom函數(shù)產(chǎn)生的隨機(jī)數(shù)在0~1之間,所以乘以10再向下取整就是0~9之間的隨機(jī)數(shù)了。
慕無忌4501192
var num=Math.random*9;
舉報(bào)
本課程從如何插入JS代碼開始,帶您進(jìn)入網(wǎng)頁動態(tài)交互世界
2 回答關(guān)于Random產(chǎn)生隨機(jī)數(shù)的問題
2 回答隨機(jī)數(shù) random()
5 回答怎么用random()和round()生成一個隨機(jī)整數(shù)?
2 回答可以用round(),random()這兩種方法隨機(jī)生成10個不同的數(shù)嗎/用for循環(huán)可以嗎?
4 回答有大佬知道如何用random和round方法輸出0~10;不相等的整數(shù)???
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2019-03-17
<script type="text/javascript">
document.write(Math.round(Math.random()));
</script>
2019-02-26
var num=Math.floor(Math.random()*10);因?yàn)閞andom函數(shù)產(chǎn)生的隨機(jī)數(shù)在0~1之間,所以乘以10再向下取整就是0~9之間的隨機(jī)數(shù)了。
2019-02-23
var num=Math.random*9;