clairec666
11-11-2003, 06:25 AM
I have found scripts that select 6 random numbers, like a random lottery, but how can I let the user select how many numbers they want to pick?
The scripts I have found already look something like this:
var pick = new Array(6);
for (i=0; i<6; i++) {
pick[i] == "":
}
while(pick[5] == "") {
var j = Math.ceil(Math.random()*49);
if(pick[0]=="") pick[0]=j;
else if(pick[1]==""&&j!=pick[0]) pick[1]=j;
else if(pick[2]==""&&j!=pick[1]&&j!=pick[0]) pick[2]=j;
etc., where I have to compare the random number to all the already selected numbers each time to see if it has already been chosen.
How would I do this with an undefined number of numbers to be picked?
The scripts I have found already look something like this:
var pick = new Array(6);
for (i=0; i<6; i++) {
pick[i] == "":
}
while(pick[5] == "") {
var j = Math.ceil(Math.random()*49);
if(pick[0]=="") pick[0]=j;
else if(pick[1]==""&&j!=pick[0]) pick[1]=j;
else if(pick[2]==""&&j!=pick[1]&&j!=pick[0]) pick[2]=j;
etc., where I have to compare the random number to all the already selected numbers each time to see if it has already been chosen.
How would I do this with an undefined number of numbers to be picked?