zoukankan      html  css  js  c++  java
  • javascript Math.random()随机数函数

    返回指定范围的随机数(m-n之间)的公式 ,大家可以参考下。

    random函数语法
    Math.random();
    random函数参数
    无参数
    random函数返回值
    返回0和1之间的伪随机数,可能为0,但总是小于1,[0,1)
    random函数示例
    document.write(Math.random());
    返回随机数
    document.write(Math.random()*(20-10)+10);
    返回10-20的随机数
    document.write(Math.random()*(n-m)+m);
    返回指定范围的随机数(m-n之间)的公式 

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
          alert(Math.round(Math.random()*(10000-1000)+1000));    
    </script>
    </head>
    
    <body>
    </body>
    </html>
  • 相关阅读:
    JavaScript基础学习篇
    js,html,css注释大集合
    JS中的专业术语
    BFC给我的帮助以及对hasLayout的认识
    框架
    PHP echo和print语句
    PHP变量
    PHP语法
    PHP入门
    SQLite学习网址
  • 原文地址:https://www.cnblogs.com/Harry369/p/3082879.html
Copyright © 2011-2022 走看看