I am learning C and I am trying to get a random float number between 10 and 20. This is what I have so far:
srand(time(NULL));
float x = (float) rand() / (float) (RAND_MAX) * 10 + 20;
printf("%f\n", x );
Whenever I run it only gives me a number that's something like so 20.103979. What am I doing wrong and how can I correct it?
Aucun commentaire:
Enregistrer un commentaire