代码示例:(标识:eg_js_random)
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Math.random()</h2>

<p>Math.random() 返回 0(包含)和 1(不包括)之间的随机数:</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = Math.random();
</script>

</body>
</html>
运行结果: