samedi 28 août 2021

C - Trying to generate random value between 0-6 but getting errors

I am trying to generate a random value between 0-6 for my game however using this function I get given two errors. This is the code:

int get_random_gesture() {
    return (rand()/((double)RAND_MAX + 1)) * 6;
}

The errors I am receiving in my IDE are as follows:

error: implicit declaration of function 'rand' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    return (rand() /((double)RAND_MAX + 1)) * 6;
            ^
error: use of undeclared identifier 'RAND_MAX'
    return (rand() /((double)RAND_MAX + 1)) * 6; 
                             ^

Does anyone have an idea how to fix these errors?

Cheers.




Aucun commentaire:

Enregistrer un commentaire