I am trying to generate random results, such as from a coin flip. I'd like to run this A/B or heads/tails generator until I get x of the same result consecutively.
I found this code online for a coin flip:
sample.space <- c(0,1)
theta <- 0.5 # this is a fair coin
N <- 20 # we want to flip a coin 20 times
flips <- sample(sample.space,
size=N,
replace=TRUE,
prob=c(theta,1-theta))
This works to generate 20 flips, but what I want to do is have the 'flip simulator' run until I get x of the same result in a row.