js之Math对象

        var num = Math.random()*10;
        var num1 = Math.floor(num); // 向下取整
        var num2 = Math.ceil(num); // 向上取整
        document.write(num2+'-<br>');
        document.write(num1);

        // 1-10 随机数
        var a = Math.floor(Math.random()*10+1);
        console.log(a);

        function selectForm(min,max){
            var ta = max - min + 1;
            return Math.floor(Math.random() * ta + min);
        }
        console.log(selectForm(3,5));

        var colors = ["red","gree","blue","yellow","black"];
        var color = colors[selectForm(0,colors.length-1)];
        console.log(color);                
原文地址:https://www.cnblogs.com/pangzi666/p/5607133.html