I am currently running a small simulation and am irritated by the results. This is my code:
ground_truth <- c("coke", "zero", "light", "zero")
options <- c("zero", "coke", "light")
random_guess<- lapply(1:10000, function(x){
first <- sample(options, 1)
rest <- sample(options, 3)
return(c(first, rest))
})
final_res <- lapply(random_guess, function(k) {
sum(k == ground_truth)
}) %>% unlist()
table(final_res)
I noticed that no matter how often I generate random guesses, the code never returns a perfect match with the ground truth which seemes unlikely (impossible). I made a small adjustment to the code and changed return(c(first,rest))
return(c(rest, first))
and now i do get from time to time a full match with the ground truth. However this really confuses me since I thought everything is picked randomly anyway. Doing the following change return(sample(c(first,rest)))
also returns the correct results.
Any insights into why this is happening are very much appreciated!