Javascript或jQuery方法产生任意随机整数
方法1:javascritp方法
| 1 2 3 4 5 6 | //随机数   functiondiu_Randomize(b,e){       if(!b && b!=0 || !e){return"?";}       returnMath.floor( ( Math.random() * e ) + b );   }   $(window).load = $(".ps"+diu_Randomize(1,12)).show();//1-12之间的随机数,包括1和12   | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | document.write(parseInt(10*Math.random()));  //输出0~10之间的随机整数      document.write(Math.floor(Math.random()*10+1));  //输出1~10之间的随机整数      functionRndNum(n){      varrnd="";      for(vari=0;i<n;i++)      rnd+=Math.floor(Math.random()*10);      returnrnd;      }      document.write(RndNum(4));  //输出指定位数的随机数的随机整数      //1. 从1开始 至 任意值      parseInt(Math.random()*上限+1);       //2. 从任意值开始 至 任意值      parseInt(Math.random()*(上限-下限+1)+下限);       functionfRandomBy(under, over){       switch(arguments.length){       case1: returnparseInt(Math.random()*under+1);       case2: returnparseInt(Math.random()*(over-under+1) + under);       default: return0;       }       }       document.write(fRandomBy(1,100));  //输出指定范围内的随机数的随机整数    | 
方法2:jQuery方法
| 1 2 3 4 5 6 7 | $(document).ready(function() {        //x上限,y下限         varx = 12;         vary = 0;         varrand = parseInt(Math.random() * (x - y + 1) + y);        $("#b").html("").append("<div>"+ rand + "</div>");     })     | 
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号