js产生随机数

 

js一定范围内随机的数字

//根据最大值和最小值生成随即数

        function fRandomBy(under, over) {

            switch (arguments.length) {

                case 1: return parseInt(Math.random() * under + 1);

                case 2: return parseInt(Math.random() * (over - under + 1) + under);

                default: return 0;

            }

        }  
例如 产生1到10的随机数
var n=fRandomBy(1,10);
 

 

 

 

你可能感兴趣的:(随机数)