【技术】0-1000的随机数

控制台里显示0-1000的随机数:

 

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>test3</title>
    <script src="js/jquery-1.11.1.min.js"></script>

  </head>
  <body>

    <script>
    function fn(){

      //Math.random():0到1随机数

      //Math.random()*1000:0到1000随机数

      //Math.ceil(Math.random()*1000):向上取整

      var str = Math.ceil(Math.random()*1000);
      console.log(str);

//每1秒输出一个随机数

      setTimeout("fn()",1000);
    }

    fn();

    </script>

  </body>
</html>

posted @ 2014-09-13 22:49  ybingbing_1213  Views(1572)  Comments(0)    收藏  举报