js随机生成一组指定区间的数组

        function randomArray(start,end){
                    var a=[],o={},random,step=end-start;
                    while(a.length<step){
                            random=start+parseInt(Math.random()*step);
                            if(!o["x"+random]){
                                    a.push(random);
                                    o["x"+random]=1;
                                };
                        };
                    return a;
            };

Demo:

randomArray(0,10);//返回一个长度为10,元素不重复的0-9的值
posted @ 2012-11-22 14:25  一只帅蚂蚁  阅读(721)  评论(0)    收藏  举报