生日悖论
dupli <- function(result){
for (i in 1:length(result)){
if (duplicated(result)[i]==T){
return(1)
break()
}
}
}
sampl <- function(N){
Num <-0
for(j in 1:N){
set.seed(j)
result <- sample(1:365,50,replace = T)
Num <- sum(Num,dupli(result),na.rm = T)
if (j==N){
return(Num)
}
}
}
sampl(1000)/1000
for (i in 1:length(result)){
if (duplicated(result)[i]==T){
return(1)
break()
}
}
}
sampl <- function(N){
Num <-0
for(j in 1:N){
set.seed(j)
result <- sample(1:365,50,replace = T)
Num <- sum(Num,dupli(result),na.rm = T)
if (j==N){
return(Num)
}
}
}
sampl(1000)/1000
评论
发表评论