Advertisement
icebowl

random-words.cpp

May 12th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>       /* time */
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. string RandomWord(int wordlength);
  10.  
  11. int main ()
  12. {
  13.         /* initialize random seed: */
  14.     srand (time(NULL));
  15.     string theword;
  16.     int i, num = 4;//num is how long word is
  17.     for( i = 0; i < 100000000; i++){
  18.         theword = RandomWord(num);
  19.         if ("MEOW" == theword){
  20.             cout<<"****************************** HIT ************************"<<endl;
  21.         cout<<i<<" "<<theword<<" ";
  22.  
  23.         }
  24.     }
  25.     return 0;
  26. }
  27.  
  28. string RandomWord(int wordlength){
  29.     string aword;
  30.  
  31.     int i, randomInt;
  32.     int val = 0;
  33.     char letter;
  34.  
  35.      for(i = 0; i < wordlength;i++)  {
  36.         randomInt = rand() % 26 + 65;
  37.         letter = (char)randomInt;
  38.         string aletter (1,letter);
  39.         aword = aword + aletter;
  40.         //cout<<i<<" * ";
  41.     }
  42.  
  43. return aword;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement