title: C++ Random Name Generator giving repeat string
body: <p>I've pieced together a small program designed to build random names. It is not finished, however it is currently repeating the same name if I attempt to re-run the program. Program is built on Ubuntu Linux, C++ running the emacs text editor. </p>
  
  <p>Here is the full code below, I am still fairly new to C++ but haven't encountered this issue before. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;iomanip&gt;
  #include &lt;stdlib.h&gt;
  
  using namespace std;
  
  
  string randomName(int length) {
  
    char consonents[] = {'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z'};
    char vowels[] = {'a','e','i','o','u','y'};
  
    string name = "";
  
    int random = rand() % 2;
    int count = 0;
  
    for(int i = 0; i &lt; length; i++) {
  
      if(random &lt; 2 &amp;&amp; count &lt; 2) {
        name = name + consonents[rand() % 19];
        count++;
      }
      else {
        name = name + vowels[rand() % 5];
        count = 0;
      }
  
      random = rand() % 2;
  
    }
  
    return name;
  
  }
  
  
  int main() {
  
    cout &lt;&lt; "Enter a name length: " &lt;&lt; endl;
  
    int length;
  
    cin &gt;&gt; length;
  
    cout &lt;&lt; randomName(length) &lt;&lt; endl;
  
    return 0;
  
  }
  </code></pre>
  
  <p>I have read the predictability for rand() and in the other questions that were similar to this they mention that rand() often repeats values. Surely this can't be every single time the program is run though can it? </p>
  
  <p>In example: 
  If I run the program with a name length of 5 I may get something like: tfuvi</p>
  
  <p>If I then run the program a second time with a name length of 2 I will get: tf</p>
  
  <p>If I then run the program a third time with the name length of 4 I will get: tfuv</p>
  
  <p>This can't be coincidence right?</p>
  
  <p>Any help is greatly appreciated, if there is any documentation that explains this or if anyone knows a reason please let me know, thanks.</p>