1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include <cstdio>
#include <cstdlib>
#include <ctime>
#define N 1000000
using namespace std;
double rand_double();
int Random(int Max);
void dicewtfone();
void dicewtftwo(int argc, char* argv[]);
int main(int argc, char* argv[])
{
dicewtfone();
dicewtftwo(argc, argv);
}
void dicewtfone()
{
int d[7];
int i, k, roll, num1, num2, num3;
srand((28420));
for (i = 1; i < 7; i++) d[i] = 0;
for (k = 0; k < N; k++)
{
roll = (int)(6.0*rand_double() + 1.0);
d[roll]++;
}
for (i = 1; i < 7; i++)
printf("%2i: %6i :\n", i, d[i]);
}
double rand_double()
{
return rand() / (double)RAND_MAX;
}
void dicewtftwo(int argc, char* argv[])
{
int i, num1, num2, num3;
int totals[19];
srand((28420));
for (i = 3; i <= 18; i++)
totals[i] = 0;
for (i = 0; i < N; i++)
{
int d1 = Random(6);
int d2 = Random(6);
int d3 = Random(6);
int total = d1 + d2 + d3;
totals[total]++;
}
for (i = 3; i <= 18; i++)
printf("%2i: %6i : \n", i, totals[i]);
}
int Random(int Max)
{
return (rand() % Max) + 1;
}
|