Just for fun - as mentioned the particular implementation of rand()/srand() may produce better, or worse, results.
For 20 samples (absurdly low, I know) I get
Code:
Value Method 1 Method 2
0 8 (0.40000) 7 (0.35000)
1 12 (0.60000) 13 (0.65000)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define DICE_SIDES 2
#define NUMBER_ROLLS 20
int main(void)
{
unsigned dist1[DICE_SIDES],
dist2[DICE_SIDES],
i;
/* srand(time(NULL)); */
memset(dist1, 0, sizeof dist1);
memset(dist2, 0, sizeof dist2);
for (i = 0; i < NUMBER_ROLLS; i++) {
dist1[rand() % DICE_SIDES]++;
dist2[(int)((double)rand() / RAND_MAX * DICE_SIDES)]++;
}
printf("%5s %25s %25s\n", "Value", "Method 1", "Method 2");
for (i = 0; i < DICE_SIDES; i++)
printf("%5u %15u (%.5f) %15u (%.5f)\n", i,
dist1[i], dist1[i] / (double)NUMBER_ROLLS,
dist2[i], dist2[i] / (double)NUMBER_ROLLS);
return 0;
}