vendredi 19 février 2021

how to use a random number generator with arrays in C

I am making a game and I need to use a random number generator. I need it to take something from an array and need stuff in the array to have a different probability of getting picked from the array. here's my code (note: the chance of the number getting picked goes down with each number)

int randomInt(int lower, int upper) 
{ 
    int num;
    int s; 
    for (s = 0; s < 1; s++)
    { 
        num = (rand() % 
           (upper - lower + 1)) + lower; 
    }
    return num; 
} 


const char *yes[5] {"one", "two", "three", "four", "five"};



Aucun commentaire:

Enregistrer un commentaire