So this works for 10 random integers between 1 and 100:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
for (int i = 0; i < 10; i++) {
int random = rand() % 100 + 1;
printf("The random integer is: %d\n", random);
}
}
However, if I want to randomly generate doubles in the range, how would I go about it? I tried changing the declaration of random
to double
and used casting on the RHS like this:
double random = (double) rand() % 100 + 1;
I hope this question is well formulated.