lundi 20 mai 2019

Probability of happening function

Basically I have a race, in every lap of the race each pilot have 5% probability of crashing.

How can I make a function that test the probability of crashing?


//the professor gave us this code but wasn't able to use it/ or understand it

//Returns the value 1 with probability prob. Otherwise, return 0

int probEvent(float prob){
    return prob > ((float)rand()/RAND_MAX);
}






Aucun commentaire:

Enregistrer un commentaire