Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //~~~~~ MAIN PROGRAM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`',
- //```````````````````````````````````````````````````````````````````````````````````
- int main() {
- //random seed
- randSeed();
- //run R5
- int tNum; //roll count
- int A; //first die count
- int B; //second die count
- //get info from user
- printf("enter roll count:"); scanf("%d",&tNum);
- printf("enter first die count:"); scanf("%d",&A);
- printf("enter second die count:"); scanf("%d",&B);
- //run simulation
- double CR_TOT = 0.0;
- int z;
- int dieA[tNum];
- int dieB[tNum];
- printf("dieA\tdieB\tRAB\t\tCR\n");
- for (z = 0; z < tNum; z++) {
- int k;
- rollFunc(&k,A);
- dieA[z] = k;
- rollFunc(&k,B);
- dieB[z] = k;
- double COEFF_A = B*1.0/((A+B)*1.0);
- double COEFF_B = A*1.0/((A+B)*1.0);
- double RAB;
- RAB = COEFF_A*dieA[z] + COEFF_B*dieB[z];
- double DEN = 2.0*A*B/((A+B)*1.0);
- double NUM = B*1.0/((A+B)*1.0) + A*1.0/((A+B)*1.0);
- double CR;
- CR = (RAB - NUM)/(DEN - NUM);
- CR_TOT += CR;
- printf("%d\t%d\t%f\t%f\n",dieA[z],dieB[z],RAB,CR);
- }
- CR_TOT = CR_TOT/tNum;
- printf("Average on Roll Stack: %f\n",CR_TOT);
- return 0;
- }
- //~~~~~ FUNCTIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`',
- #include"statDefs.h" //statisticl algorithms
- #include"arrayDefs.h" //array methods
- #include"determinant.h" //classic determinant
- #include"linearAlgebra.h" //linear algebraic methods
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ ~ ~ ~
- // ^^^ ABOVE IS OFTEN BLOATED AS CODE IS COPIED UNTIL PURSUED IN ACTIVE MARKET ^^^
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`',
- //~~~~~ functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`',
- void dUb(int *kIn) {
- double RAND = pRand();
- if(RAND < 0.5) {*kIn = 1;}
- else {*kIn = 2;}
- }
- void tRp(int *kIn) {
- double RAND = pRand();
- if(RAND < 0.25) {*kIn = 1;}
- else if (RAND < 0.5) {*kIn = 2;}
- else if (RAND < .75) {*kIn = 3;}
- else {tRp(kIn);}
- }
- //variate roll functor
- void rollFunc(int *rOut,int A) {
- double RAND = pRand();
- double STEP = 1.0/A;
- double CHECK = STEP;
- int RESPONSE = 1;
- while (CHECK < RAND) {
- RESPONSE += 1;
- CHECK += STEP;
- }
- *rOut = RESPONSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement