Advertisement
Radfler

::make_random_string

Sep 22nd, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <random>
  2. #include <string>
  3. #include <utility>
  4.  
  5. template<typename URNG>
  6. std::string make_random_string(std::size_t length, URNG&& generator) {
  7.  
  8.     std::uniform_int_distribution<int> distribution(0x21, 0x7E);
  9.     std::string result;
  10.  
  11.     while(length) {
  12.  
  13.         result += distribution(std::forward<URNG>(generator));
  14.         --length;
  15.  
  16.     }
  17.  
  18.     return result;
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement