C++ : Read random line from text file
<p>I am trying to code a program that picks 3 random lines from a text file (that contains 50 lines) and outputs them to the screen.</p>

<p>Here is my current code:</p>

<pre><code>string line;
int random = 0;
int numOfLines = 0;
ifstream File("file.txt");

    srand(time(0));
    random = rand() % 50;

while(getline(File, line))
{
    ++numOfLines;

    if(numOfLines == random)
    {
        cout &lt;&lt; line;
    }

}
</code></pre>

<p>I can get it to print one random line like it does above but not three random lines.</p>