Advertisement
WeltEnSTurm

Untitled

Nov 24th, 2011
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <string>
  7.  
  8. std::string randomstring(int len) {
  9.     static long seed = time(0);
  10.     seed += rand();
  11.     srand(seed);
  12.     std::string s;
  13.     for(int i=0; i<len; ++i) {
  14.         int r = rand() % 3;
  15.         s.push_back(
  16.             r == 0 ? rand()%(90-65) + 65
  17.             : r == 1 ? rand()%(57-48) + 48
  18.             : rand()%(122-97) + 97
  19.         );
  20.     }
  21.     return s;
  22. }
  23.  
  24.  
  25. int main() {
  26.     for(int i=0; i<20 ;i++)
  27.         std::cout<<i<<" - "<<randomstring(10)<<std::endl;
  28.     std::cin.get();
  29.     return 0;
  30. }
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement