1//get random value from array
2var colors = ["red","blue","green","yellow"];
3var randColor = colors[Math.floor(Math.random() * colors.length)];
4
1function getRandom(arr, n) {
2 var result = new Array(n),
3 len = arr.length,
4 taken = new Array(len);
5 if (n > len)
6 throw new RangeError("getRandom: more elements taken than available");
7 while (n--) {
8 var x = Math.floor(Math.random() * len);
9 result[n] = arr[x in taken ? taken[x] : x];
10 taken[x] = --len in taken ? taken[len] : len;
11 }
12 return result;
13}