zoukankan      html  css  js  c++  java
  • 编写函数实现随机产生指定范围的整数的功能

    //.编写函数实现随机产生指定范围的整数的功能
    /*[1,10]
    [0,1)*10=[0,10)----->+1---->[1,11)---->下取整  Math.floor   window.parseint()*/
    /*[2,9]
    [0,1)--->[0,8)--->[2,10)*/

    var random_fun = function(start,end){
     var random  = Math.floor(Math.random()*(end-start+1)+start);
     return random;
    }
    var end,start;
    start = prompt("请输入起始值:")*1;
    end   = prompt("请输入结束值:")*1;
    var result = random_fun(start,end);
    document.write(start+"到"+end+"的随机整数为:"+result);

    欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
  • 相关阅读:
    Linux
    Python
    Linux
    Python
    爬虫
    WEB
    法正(13):密谋
    法正(12):张松
    法正(11):入川
    法正(10):袍哥
  • 原文地址:https://www.cnblogs.com/flyingcr/p/10428337.html
Copyright © 2011-2022 走看看