简单的生成随机数
Posted 宁丹妮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单的生成随机数相关的知识,希望对你有一定的参考价值。
<html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <body> <script> //生成0-10的随机数 乘10 加1得到的是浮点数 var random = Math.random() * 10 + 1; // console.log(random); // 向下取整 var ran = Math.floor(random); console.log(ran); </script> </body> </html>
以上是关于简单的生成随机数的主要内容,如果未能解决你的问题,请参考以下文章