怎么實(shí)現(xiàn)生成一個(gè)隨機(jī)整數(shù)?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
var x;
x = document.write(Math.random());
document.write(Math.round(x));
</script>
</head>
<body>
</body>
</html>
2018-08-13
上面這行代碼就生成1到10之間的隨機(jī)整數(shù)
2018-08-24
document.write(Math.round((Math.random())*10));
2018-08-13
Math.random();是隨機(jī)0~1之間的數(shù);
Math.random()*10;隨機(jī)1~10之間的數(shù);
Math.round(Math.random()*10); 隨機(jī)1~10之間的整數(shù);
//random()隨機(jī)數(shù);
//round()四舍五入為整數(shù);