課程
/前端開發
/JavaScript
/JavaScript進階篇
怎么用random()和round()生成一個隨機整數?
2018-09-27
源自:JavaScript進階篇 7-16
正在回答
? 在? math? 里面【四舍五入? (生產1~10隨機數)】
so:? ?document.write(? ?Math.round(? Math.random()*10 ) );
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
var a=Math.random()*10;
var b=Math.round(a);
document.write(b);
</script>
</head>
<body>
</body>
</html>
document.write(Math.round(Math.random()*10));
Math.round(Math.random()*10) 隨機生成0-10的整數
本來是先用random(),在random里套round,結果發現隨機生成的不是整數
舉報
本課程從如何插入JS代碼開始,帶您進入網頁動態交互世界
3 回答怎么實現生成一個隨機整數?
2 回答隨機數 random()
2 回答可以用round(),random()這兩種方法隨機生成10個不同的數嗎/用for循環可以嗎?
1 回答使用random()和round()計算不大于10的整數
3 回答如何用random()產生0-9的隨機數
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-12-26
? 在? math? 里面【四舍五入? (生產1~10隨機數)】
so:? ?document.write(? ?Math.round(? Math.random()*10 ) );
2018-11-29
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
var a=Math.random()*10;
var b=Math.round(a);
document.write(b);
</script>
</head>
<body>
</body>
</html>
2018-10-30
document.write(Math.round(Math.random()*10));
2018-09-28
Math.round(Math.random()*10) 隨機生成0-10的整數
2018-09-27
本來是先用random(),在random里套round,結果發現隨機生成的不是整數