Alex Lord Alex Lord - 1 month ago 14
C Question

C - Frequency of Randomly Generated Numbers

If I put

i < 100
or
i < 1000
in the for loop, it will generate 100/1000 numbers, respectively.
However, when I put 10000, nothing appears when I run it, why is this?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
int i;
int random_number;

srand((unsigned)time(NULL));

for (i = 0; i < 10000; i++) {
random_number = (int) (10.0 * rand() / (RAND_MAX + 1.0));
printf("%d", random_number);

}

return 0;
}


I have been tasked to tabulate the percentage of 10,000 (0-9) random numbers. So any help at all with further code for this would also be greatly appreciated.

(I am new to C and StackOverflow so I am still learning how to use both - so I apologise in advance if I have used either of them wrong!)

EDIT : Whole code has been added now. I am using Eclipse and when I run this I still get nothing.

Thank you!

Answer

I copy your code to DEVC++ and run it.
It worked correctly you can see codes in the picture :
enter image description here

enter image description here

Comments