1//This example is to generate an array with 40 random elements, with random values from 0 to 39
2
3for (var a=[],i=0;i<40;++i) a[i]=i;
4
5// http://stackoverflow.com/questions/962802#962890
6function shuffle(array) {
7 var tmp, current, top = array.length;
8 if(top) while(--top) {
9 current = Math.floor(Math.random() * (top + 1));
10 tmp = array[current];
11 array[current] = array[top];
12 array[top] = tmp;
13 }
14 return array;
15}
16
17a = shuffle(a);
18
1var arr = [];
2while(arr.length < 8){
3 var r = Math.floor(Math.random() * 100) + 1;
4 if(arr.indexOf(r) === -1) arr.push(r);
5}
6console.log(arr);