By my secondary school math, the odd to match all 6 numbers out of 49 numbers is:
49!
1 : ---------------------
(49-6)! 6!
or
1 : 13983816, about 1: 14 million
However, when I write a program to simulate that, it takes more than 280 million tickets to match one, do I just have a bad random number generator?
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "stdafx.h"
int main(int argc, char* argv[])
{
long count=0, millcount=0;
int lottnum, lottwinnum[6], match=0;
for(int i=0;i<6;i++){
lottwinnum=int(double(rand())/RAND_MAX*49)+1;
printf("%d ", lottwinnum);
}
printf("\n"
;
while(match!=6){
for (int j=0;j<6;j++){
lottnum=int(double(rand())/RAND_MAX*49)+1;
if (lottnum==lottwinnum[j])
match++;}
count++;
if (count>1000000){
count=0;
millcount++; }}
printf("The lotto numbers are matched after %ld million %ld tickets!\n", millcount, count);
return 0;
}
Run:
The lotto numbers are matched after 288 million 571671 tickets!
49!
1 : ---------------------
(49-6)! 6!
or
1 : 13983816, about 1: 14 million
However, when I write a program to simulate that, it takes more than 280 million tickets to match one, do I just have a bad random number generator?
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "stdafx.h"
int main(int argc, char* argv[])
{
long count=0, millcount=0;
int lottnum, lottwinnum[6], match=0;
for(int i=0;i<6;i++){
lottwinnum=int(double(rand())/RAND_MAX*49)+1;
printf("%d ", lottwinnum);
}
printf("\n"
while(match!=6){
for (int j=0;j<6;j++){
lottnum=int(double(rand())/RAND_MAX*49)+1;
if (lottnum==lottwinnum[j])
match++;}
count++;
if (count>1000000){
count=0;
millcount++; }}
printf("The lotto numbers are matched after %ld million %ld tickets!\n", millcount, count);
return 0;
}
Run:
The lotto numbers are matched after 288 million 571671 tickets!