What is the probability that the algorithm below writes out2?
i = 0
while rand(1,2) != rand(1,2)
i++
print i
Explain well!
Answer
Here we are generating the number between 1 and 2 so here
1/2=.5 so we have 50% probability to write the number 2