Advertisement
WeltEnSTurm

Untitled

Nov 24th, 2011
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1.  
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <string>
  5.  
  6. std::string randomstring(int len) {
  7.     srand((long)time(0));
  8.     std::string s;
  9.     for(int i=0; i<len; ++i) {
  10.         int rand = rand() % 3;
  11.         s.append(
  12.             rand == 0 ?
  13.                 s = rand()%(90-65) + 65 //A-Z
  14.             : rand == 1 ?
  15.                 s = rand()%(57-48) + 48 //0-9
  16.             : rand()%(122-97)+97 //a-z
  17.         );
  18.     }
  19.     return s;
  20. }
  21.  
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement