mardi 25 août 2015

I need to generate a group of random numbers between 97 and 122

I have to generate random numbers between 97 and 122 using a specific algorithm but I get numbers that are greater than 122. Here is the code:

srand( time (NULL));

int num;
unsigned i;

for (i = 0;i<100;i++){

    num = 97+(rand()%122);

        printf("%d\n",num );

}

return 0;




Aucun commentaire:

Enregistrer un commentaire