Please Help with my Random Name Generator

Hello
This is my Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
    const string wordList1[4] = { "ancient", "hollow", "cobbler", "death" };

    string word1 = wordList1[rand() % 4];

    srand(time(0));

    const string wordList2[4] = { "alley", "castle", "place", "cave" };

    string word2 = wordList2[rand() % 4];


    cout << word1 << " "<< word2 << endl;

    return 0;
}


I'm trying to have individual lines in a text document I can alter and than use this program to create random names.
I'm trying to put this into a text document

1
2
3
4
5
6
7
8
9
    const string wordList1[4] = { "ancient", "hollow", "cobbler", "death" };

    string word1 = wordList1[rand() % 4];

    srand(time(0));

    const string wordList2[4] = { "alley", "castle", "place", "cave" };

    string word2 = wordList2[rand() % 4];


Edit
Also for some reason when ever I run the program it always uses "hollow" why does it do this?

Any help would be great thank you.
Last edited on
Put the srand(time(0)) at the top of main. You're calling the rand function before you even seed it. Also, if you ever decide to use rand and srand again, remember that you only have to seed it once.
Thank you deathslice
This has fixed up the bug
still trying to figure out though how to put these names into files and access them from there.
Topic archived. No new replies allowed.