How to use probabilities in loops?

Hi, suppose i want to run a loop that involves an object(real-life meaning)
that chooses two directions: one of the directions returns back to the original position, while the other direction has two probabilities associated with it:
e.g. 1/3 chance the loop will end, and 2/3 chance it will return to original position..

my question is how do i program this or what to put in the body of the loop?
i've never done any probability stuff in c++ so i am confused on how to do this.. does it involve rand()?
Last edited on
If rand() % 3 is a uniformly distributed random variable, then the probability
of rand() % 3 returning 0 is 1/3 and returning non-zero is 2/3.

Topic archived. No new replies allowed.