今天需要用到随机数,我还以为像java有个随机数类,结果在Math类里面,我需要取的是整数,0-15,取10个,不能重复,代码如下:

代码
var itn:Array = new Array();
                    
while(itn.length != 10){
//最主要的代码就是下面这句,你要取多大,后面模一下,我觉得这样挺方便的~
                        var temp:int = (Math.random()*1000>>0)%16;
                        trace(
"这次出来的是: "+temp);
                        
if(itn.length != 0){
                            
for(var h:int = 0;h<itn.length;h++){
                                
if(temp == itn[h]){
                                    h 
= 0;
                                    temp 
= (Math.random()*1000>>0)%16;
                                }
                            }
                        }
                        itn.push(temp);
                    }
 trace(
"全部数字是: "+itn);

 


posted on 2010-04-16 14:49  钱途无梁  阅读(804)  评论(0编辑  收藏  举报