fork(1) download
  1. #include <algorithm>
  2. #include <ctime>
  3. #include <functional>
  4. #include <iostream>
  5. #include <random>
  6. #include <string>
  7.  
  8. int main()
  9. {
  10. const std::size_t defaultStringLength = 50;
  11.  
  12. //std::random_device seed;
  13. //std::mt19937 prne(seed());
  14. // random_device is way better, but no access to hardware at ideone
  15. std::mt19937 prne( std::time(NULL) );
  16.  
  17. std::vector<double> bounds = {'A', 'Z'+1, 'a', 'z'+1};
  18. std::vector<double> weights = { 1, 0, 1};
  19. std::piecewise_constant_distribution<> d(bounds.begin(), bounds.end(), weights.begin());
  20.  
  21. std::string s(defaultStringLength, ' ');
  22.  
  23. std::generate(s.begin(), s.end(), bind(d, ref(prne)));
  24.  
  25. std::cout << s << '\n';
  26. }
  27.  
Success #stdin #stdout 0s 3024KB
stdin
Standard input is empty
stdout
MRtwRNZtYFyMaoKTJrlGAehSHvpKoZwvsIdmCGqRRXApWtMRAC