js 生产[0,20)之间的随机整数.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>random</title>
</head>

<body>
    <script>
        // Math.floor(x) -> 返回值小于等于 x,且与 x 最接近的整数。
        // Math.random() -> 返回介于 [0 ~ 1) 之间的一个随机数。
        for(var i=0;i<200;i++){
            console.log(Math.floor(Math.random() * 20));
            // 打印值介于[0,20)之间。
        }
    </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/87855885
今日推荐