jeudi 21 janvier 2016

Running Part of Code with a Specified Probability

I have a variable cnt, whose value is checked via an if/else statement as follows:
If cnt<=2, then call func
Else if cnt > 2, then call func with the probability of P=3/(2*cnt).
How can I implement this probability-based execution of code in C++?

void func() {
    sendMsg();
}




Aucun commentaire:

Enregistrer un commentaire