Possible Duplicate:
Generate unique number within range (0 - X), keeping a history to prevent duplicates
Writing a function that make random array,as I wrote below:
RandomArray(10)
=> [0,2,3,9,6,5,4,7,8,1]
:(
I'm not learning progarming when school days so i wrote a ugly one.Here is my program.
var min = 0,
max = 15, //Here generate an random array from 0-14
i,
j,
arr = [],
temp = [];
for (i = min;i<max; i++){
arr.push(i);
}
for(j=min;j<1000;j++){
temp.push(arr[Math.floor(Math.random() * arr.length)]);
}
function unique(array){
var b = [];
for(var i=0; i<array.length; i++){
if(b.indexOf(array[i]) == -1) b.push(array[i]);
}
return b;
}
alert(unique(temp));
I wrote this program by searching the internet,it's not perfect i think, there is no arithmetic in it...