<script>
function rand_nums(min,max,count){
var arr = [];
for(var i=min;i<max;i++){
arr.push(i);
}
var nums = [];
var temp = 0;
for(var i=0;i<count;i++){
var j = Math.floor((Math.random()*(count -i)+i));
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
nums[i] = arr[i];
}
return nums;
} var arr = rand_nums(0,5000,5000);
console.log(arr.length) //test
function unique(arr) {
var obj = {};
arr.forEach(function(v,i) {
obj[v] = 1
}); return Object.keys(obj)
}
console.log(unique(arr).length);
</script>
来自群里的 TAOTAO大神