I want to generate a random variable X by continuing generating U(0,1) random variables as long as their product falls below exp(-2). Then my random variable X would be equal to the number of U(0,1) random variables that was generated minus 1.
I tried using the while loop to do it but not sure why the code does not return anything in my console. Please help me point out what I did wrong?
p <- 1
counter <- 0
while(p < exp(-2)) {
u <- runif(1)
p <- p*u
counter <- counter+1
X <- counter - 1
print(X)
}