#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define DICE 6
int nrandom(int n)
{
return rand() % n;
// return n * rand() / (RAND_MAX + 1);
}
int main()
{
int hist[DICE] = {0};
int i, dice;
printf("RAND_MAX=%d\n", RAND_MAX);
srand((unsigned)time(NULL));
for (i = 0; i < 10000; i++) {
dice = nrandom(DICE);
if (dice < 0 || DICE <= dice) {
fprintf(stderr, "error: dice=%d\n", dice);
return 1;
}
hist[dice]++;
}
for (i = 0; i < DICE; i++) {
printf("%d=%d\n", i, hist[i]);
}
return 0;
}