Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <random>
  4. #include <string>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. string random_string(size_t length )
  10. {
  11.     static const string alphabet = "abcdefghijklmnopqrstuvwxyz" ;
  12.     static default_random_engine rng( time(nullptr) ) ;
  13.     static uniform_int_distribution<size_t> distribution( 0, alphabet.size() - 1 ) ;
  14.  
  15.     string str ;
  16.     while( str.size() < length ) str += alphabet[ distribution(rng) ] ;
  17.     return str ;
  18. }
  19.  
  20. int main()
  21. {
  22.     srand (time(NULL));
  23.     ofstream myfile;
  24.     myfile.open ("string.txt");
  25.  
  26.     //for( size_t i = 10 ; i < 40 ; i += 3 ) cout << random_string(i) << '\n' ;
  27.  
  28.     for(int k = 0; k < 10000; k++)
  29.     {
  30.         int range = rand() % 20 + 2;
  31.         myfile << random_string(range) << '\n';
  32.     }
  33.     myfile.close();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement