Advertisement
atimholt

Shaving: When and Whether to.

Apr 27th, 2016
1,476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. //  shavewhen.cpp
  2.  
  3. #include <cstdlib>
  4. #include <iostream>
  5. #include <random>
  6.  
  7. int main()
  8. {
  9.     std::random_device rd;
  10.     std::mt19937 mt {rd()};
  11.     std::bernoulli_distribution when {1.0f / 30.0f};
  12.     std::bernoulli_distribution whether_to {1.0f / 75.0f};
  13.    
  14.     bool shave {true};
  15.     int day_count {0};
  16.     while (!when(mt))
  17.     {
  18.         if (whether_to(mt)) shave = false;
  19.         ++day_count;
  20.     }
  21.     std::cout << "Number of days: " << day_count << "\n" << std::endl;
  22.     if (!shave)
  23.     {
  24.         std::cout << "Wait, you know what? don't even shave.\n" << std::endl;
  25.     }
  26.    
  27.     return EXIT_SUCCESS;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement