課程
/前端開(kāi)發(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ù)了。
慕無(wú)忌4501192
var num=Math.random*9;
舉報(bào)
本課程從如何插入JS代碼開(kāi)始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
2 回答關(guān)于Random產(chǎn)生隨機(jī)數(shù)的問(wèn)題
2 回答隨機(jī)數(shù) random()
5 回答怎么用random()和round()生成一個(gè)隨機(jī)整數(shù)?
2 回答可以用round(),random()這兩種方法隨機(jī)生成10個(gè)不同的數(shù)嗎/用for循環(huán)可以嗎?
4 回答有大佬知道如何用random和round方法輸出0~10;不相等的整數(shù)???
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)
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;