proffreda

Birthday Paradox: C++ Simulation

Feb 17th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.         srand(time(0));
  9.         bool            birthday  [365] = {false};
  10.         bool            done = false;
  11.         int             count = 0;
  12.  
  13.         while (!done) {
  14.                 int             next = rand() % 365;
  15.                 count++;
  16.                 if (birthday[next] == false)  
  17.                         birthday[next] = true;
  18.                 else
  19.                         done = true;
  20.         }
  21.         cout << "Count: " << count << endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment