The following code extracts five numbers in the
1..20
range, without repetitions.
var a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
var n;
var r=[];
for (n=1; n<=5; ++n)
{
var i = Math.floor((Math.random() * (20-n)) + 1);
r.push(a[i]);
a[i] = a[20-n];
}
You might try it
here[
^].
The algorithm is described here:
Random extraction of 5 cards from a deck[
^].