Advertisement
Echo89

C++11 random code generator ONLY FOR C++ 11

Nov 20th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. string random(size_t len)
  2. {
  3.     static const string a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  4.     static mt19937 x(time(NULL));
  5.     static uniform_int_distribution<size_t> d(0, a.size() - 1);
  6.     string r;
  7.     srand(time(NULL));
  8.     for(size_t i = 0; i < len; i++) r += a.at[d(x)];
  9.     return r;
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement