This JavaScript 1.1 picks a number of unique random elements from an array.
For example; if you have an array numArr consisting of 49 elements and want to pick 6 unique random elements. Suppose initially numArr[3] is picked randomly, then numArr[3] should not be picked again. The array elements can contain anything, eg; numbers, sequential numbers or animal names. Script notes inform of easy changes. If you want to pick 4 of 33 numbers, or randomise all elements in a range length "tot", you might set "tot" to equal 33 or 90 and call the function like one of these; pickNums(6,49) pickNums(4,33) pickNums(33,tot) pickNums(tot,tot) |
Reload the page to see another set of unique random elements. |