Why does this program only generate numbers from 0.1-0.2. It needs to generate numbers from 0-1.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (int argc, char *argv[])
{
/*declare pseudo-random number */
float random;
srand(time(NULL));
random = (float) rand() / (float) RAND_MAX;
printf("The random number is %f\n", random);
return 0;
}
I’m compiling using gcc on a mac.
The code seems fine to me. Try to generate more than one number and see then: