Advertisement
bueddl

random_case

Jun 18th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <random>
  5.  
  6. int main()
  7. {
  8.     std::string name = "some test";
  9.  
  10.     auto random_case = [] (auto &name) -> void
  11.         {
  12.             std::transform(name.begin(), name.end(),
  13.                 name.begin(),
  14.                 [] (unsigned char ch) -> unsigned char
  15.                 {
  16.                     static std::random_device rd;
  17.                     std::uniform_int_distribution<int> dist(0, 1);
  18.                     return dist(rd) ? std::toupper(ch) : std::tolower(ch);
  19.                 });
  20.         };
  21.  
  22.     random_case(name);
  23.  
  24.     std::cout << name << std::endl;
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement