title: Creating a function thats generates a random number using srand and rand
body: <p>Trying to create a function that generates a random number using <code>rand()</code> and <code>srand()</code>.</p>
  <p>This code prints 3 random numbers successfully:</p>
  <pre><code>//prints a random number from 1 to 10 3 times.
  void main()
  {
      int num;
      srand(time(NULL));
      num = rand() % 10;
      printf(&quot;%d\n&quot;, num);
      num = rand() % 10;
      printf(&quot;%d\n&quot;, num);
      num = rand() % 10;
      printf(&quot;%d\n&quot;, num);
  }
  
  //Output: 3 5 6
  </code></pre>
  <p>This code using a function doesn't:</p>
  <pre><code>//calls PrintRandomNumber 3 times.
  void main()
      {
          int i=0, num;
          for(i=0; i&lt;3; i++)
          {
          printRandomNumber(0, 10);
          }
      }
  
  //Prints a random numberin the range of lowestValue to highestValue.
  void printRandomNumber(int lowestValue, int highestValue)
  {
      int randomNumber = 0;
      srand(time(NULL));
      randomNumber = (rand() % (highestValue - lowestValue + 1)) + lowestValue;
      printf(&quot;%d\n&quot;, randomNumber);
  }
  //Output: 3 3 3
  </code></pre>
  <p>The problem is calling <code>srand(time(NULL))</code> multiple times.</p>
  <p>Can a function print/return a random number using <code>rand()</code> and <code>srand()</code> without having to call <code>srand(time(NULL))</code> in the main?</p>