vendredi 2 octobre 2015

generate rand7 from rand5

Here is the reference implementation and I do not understand why choose 21 here? Thanks.

public static int rand7() {
while (true) {
int num = 5 * (rand5() - 1) + (rand5() - 1);
if (num < 21) return (num % 7 + 1);
}
}

thanks in advance, Lin




Aucun commentaire:

Enregistrer un commentaire