mizonokuchi

simple gatya simulator

May 16th, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1.  
  2. #define RARE_PROBABILITY 5
  3. #define NUM_OF_RARE_CARD 6
  4.  
  5. int card[NUM_OF_RARE_CARD], i;
  6.  
  7. int is_complete(){
  8.   for(i=0;i<NUM_OF_RARE_CARD;i++)
  9.     if(!card[i])
  10.       return 0;
  11.   return 1;
  12. }
  13.  
  14. main(){
  15.   int n = 0, i, p;
  16.   srand(time(0));
  17.  
  18.   while(!is_complete()){
  19.     // congrats! you've got a rare card
  20.     if((p =rand() % 100) < NUM_OF_RARE_CARD * RARE_PROBABILITY)
  21.       card[p % NUM_OF_RARE_CARD]++;
  22.  
  23.     n++;
  24.   }
  25.  
  26.   printf("%d\n", n); // print the number of tries
  27. }
Advertisement
Add Comment
Please, Sign In to add comment