Random Word

Hello I'm in the process of trying to create a hangman game. I've got everything working great, but I'm having a problem getting a word from a text document at random. I'm able to get a word. Just not at random. Here what I've got so far.

1
2
3
4
5
6
7
8
string startWord;
string getlin;
    ifstream startWor;
    startWor.open("words.txt");


   startWor >>(startWord);
    cout<<startWord[rand() % 5];


What am I doing wrong here?
Thanks in advance.
You need to write srand(time(0)); just once when your program starts. This will ensure that the random number generator doesn't always start at the same place in the sequence.
Topic archived. No new replies allowed.