I'm currently trying to write a programme that will randomly select 6 numbers between 1 and 49 for the lottery but don't know where to start, can anyone give me some ideas or help on what to do?
Thanks, Mike..........
I'm currently trying to write a programme that will randomly select 6 numbers between 1 and 49 for the lottery but don't know where to start, can anyone give me some ideas or help on what to do?
Thanks, Mike..........
hmm
if you don't want the possibility of having 2 of the same number, i'd setup 2 arrays. One array is for the lotto numbers that are picked and the other contains all the possible lotto numbers.
it'd look something like this
const int MAXPICKED = 6;
const int MAXLOTTONUM = 49;
const int USEDNUMBER = 0;
int lottopot[MAXLOTTONUM];
int lottowin[MAXPICKED];
int x; //counter
int randnum; //will hold random number
//initialize the lotto number pot
for(x = 0 ; x < MAXLOTTONUM; x++)
lottopot[x] = x+1;
//pick numbers
for(x = 0; x < MAXPICKED ; x++)
{
do
{
randnum = /*get random number here*/;
}
while(lottopot[randnum] != USEDNUMBER);
lottowin[x] = lottopot[randnum]
lottopot[randnum] = USEDNUMBER;
}
also note that the lotto numbers in lottopot would be from 1-49, but the random number would need to be 0-48