Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <chrono>
  2. #include <random>
  3. #include <functional>
  4. #include <iostream>
  5.  
  6. template<char... Chars>
  7. class String
  8. {
  9. private:
  10.  
  11. constexpr static int count = sizeof...(Chars);
  12. constexpr static char characters[count] = { Chars... };
  13.  
  14. public:
  15.  
  16. static char Function()
  17. {
  18. static std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count());
  19. static std::uniform_int_distribution<int> distribution(0, count - 1);
  20. static auto randomIndex = std::bind(distribution, generator);
  21.  
  22. return characters[randomIndex()];
  23. }
  24. };
  25.  
  26. static const char S = String<'S', 'H', 'A', 'R', 'E',
  27. 'Y', 'O', 'U', 'R',
  28. 'P', 'A', 'S', 'S', 'I', 'O', 'N'>::Function();
  29.  
  30. int main()
  31. {
  32. std::cout << S;
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement