Last active
February 19, 2021 09:31
-
-
Save zmalltalker/63ba3a853cfa43a9b174d24d946ac6b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <cctype> | |
#include <fstream> | |
#include <iostream> | |
#include <list> | |
using namespace std; | |
string random_word(string path) { | |
ifstream file(path); | |
ifstream fileForRead(path); | |
string result; | |
string s; | |
file.unsetf(ios_base::skipws); | |
unsigned line_count = | |
count(istream_iterator<char>(file), istream_iterator<char>(), '\n'); | |
/* initialize random seed: */ | |
srand(time(NULL)); | |
/* generate secret number between 1 and number of lines in the file: */ | |
int iSecret = rand() % line_count + 1; | |
int i = 0; | |
while (getline(fileForRead, s)) { | |
if (i == iSecret) { | |
result = s; | |
} | |
++i; | |
} | |
return result; | |
} | |
int main(int argc, char *argv[]) { | |
string noun = random_word( | |
"/Users/marius/tmp/heroku-name-generator/dictionaries/nouns.txt"); | |
string adjective = random_word( | |
"/Users/marius/tmp/heroku-name-generator/dictionaries/adjectives.txt"); | |
transform(noun.begin(), noun.end(), noun.begin(), ::tolower); | |
transform(adjective.begin(), adjective.end(), adjective.begin(), ::tolower); | |
cout << adjective << "-" << noun << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment