码迷,mamicode.com
首页 > Web开发 > 详细

JS 输出指定范围内的随机数

时间:2018-05-03 14:25:18      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:function   rand   输出   tran   调用   自定义   random   定义   and   

/* 自定义函数 */
function GetRandomNum(Min,Max){
    var Range = Max - Min;
    var Rand = Math.random();
    return(Min + Math.round(Rand * Range));
} 

/* 调用函数 */
var num = GetRandomNum(4,10);

 

JS 输出指定范围内的随机数

标签:function   rand   输出   tran   调用   自定义   random   定义   and   

原文地址:https://www.cnblogs.com/phpfensi/p/8984916.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!