jeudi 22 avril 2021

What's wrong with my pseudo random number generator?

I am having some trouble with my random number generator. How my program works is that the player is given a set of ninja, each with a stealth score. To progress, a ninja needs to pass a "stealth check". How they pass is a RNG will pull any whole number between 0 and the ninja's stealth score. If the RNG pulls a 0, they fail the check. The problem is, some of the ninjas have a stealth score of 1. This results in them always failing the check. After I isolated and tested the RNG separately, this is still the case. I also noticed it doesn't seem to be able to pull from the stealth score itself. For example, a ninja with a stealth score of 3 never pulls 3, only 0, 1, and 2. So, how do I fix this RNG?

int stealth_check(struct ninja student[4]){
    int stealth_pass;
    int i;
    for(i = 0; i < 4; i++){
        stealth_pass = rand() % student[i].stealth;
        printf("%d\n\n", stealth_pass);
    }
return 0;
}



Aucun commentaire:

Enregistrer un commentaire