Guest User

Untitled

a guest
Jan 23rd, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. //Times to iterate (default is 4000000000 [4 billion], which will take some time)
  6. const unsigned int TOTAL = 4000000000;
  7.  
  8. int main(int argc, char* argv[]){
  9.     unsigned int i = 0;
  10.     int j = 1000;
  11.     unsigned int doors[3] = {0, 0, 0};
  12.     unsigned int wins = 0;
  13.  
  14.     srand(time(NULL));
  15.    
  16.     //Main calculation loop
  17.     for(i = 0; i < TOTAL; i++){
  18.         int choice = rand()%3;
  19.         int tmp = rand()%3;
  20.  
  21.         if(tmp != choice) wins++;
  22.         doors[tmp]++;
  23.        
  24.         //Print completion percentage, and current win/loss percent
  25.         j--;
  26.         if(j <= 0){
  27.             printf("\rWorking Percent: %f [Completion: %u%%]", (double)((double)wins/(double)i), (unsigned int)(((double)i/(double)TOTAL)*100));
  28.             j = 10000;
  29.         }
  30.     }
  31.    
  32.     //Output data
  33.     printf("\n");
  34.     printf("One:     %u\n", (unsigned int)doors[0]);
  35.     printf("Two:     %u\n", (unsigned int)doors[1]);
  36.     printf("Three:   %u\n", (unsigned int)doors[2]);
  37.     printf("Wins:    %u\n", (unsigned int)wins);
  38.     printf("Total:   %u\n", (unsigned int)i);
  39.     printf("Percent: %f\n", (double)wins/(double)TOTAL);
  40.                
  41.  
  42.     return 0;
  43. }
Add Comment
Please, Sign In to add comment