jeudi 27 juin 2019

Generate random numbers with equal probability

Can someone please explain what's going on in for loop in this code snippet?

int rand7() {
    int sum = 0;
    int multiplier = 1;
    for (int i = 0; i < 7; i++) {
        sum = sum + rand5() * multiplier;
        multiplier = multiplier * 5;
    }
    return sum % 7;     
}




Aucun commentaire:

Enregistrer un commentaire