I am working on a project for college which models a 6/49 Lotto luck game.A ticket is created by choosing 6 different numbers from 1 to 49.I have to simulate 10^6 tickets and compare it with a lucky ticket.I want to find out the cardinal of the intersection of the 6 numbers of a random ticket and the 6 numbers of the lucky ticket. But if I do it once for the 10^6 tickets, the probability of having a ticket that maches perfectly the lucky ticket is low. So I tried to do this proccess "nr_esantion" times with 10^6 random new tickets and make an avarage.
Here is my aproach:
nr_esantion<-30es<-10^6nr_49<-1:49table_1 <- rep(0,7)table_1for(i in 1:nr_esantion){ lucky <- sample(nr_49,6,replace=FALSE)inters <- replicate(es,length(intersect(sample(nr_49,6,replace=FALSE),lucky)),simplify="array")aux <- array(table(inters))# There are situations in which at one step "i", there are no intersections of cardinal 5 or 6.if(length(aux)==5){ aux <- c(aux,0,0)}else{if(length(aux)==6){ aux <- c(aux,0)}}table_1 <- table_1+aux}table_1 <- table_1/nr_esantion
I am happy with the results I got but my problem is that one iteration, for $10^6$ tickets, it takes around 20 seconds. So for the total of 30 iterations, it takes around 10 minutes. I have to change the "nr_esantion" to 300 for some of the project tasks.
My question: Is there a faster method to compute these $10^6 * 300$ samples?