title: using rand() in a function in c
body: <p>I have made a function that creates a random number between 0 and 9 but when i call the function in main in a for loop with index i = 0 ; i &lt; n ; i++ it prints 1 random number n types. but i want different values to be printed n times. 
  here is the code which i made :-</p>
  
  <pre><code>    #include&lt;stdio.h&gt;
      #include&lt;stdlib.h&gt;
      #include&lt;time.h&gt;
      void random_variable() {
       int i;
       srand(time(NULL));
       i = rand()%10;
       printf("%d ",i);
      }
      main() {
       for(int j=0;j&lt;10;j++) {
        random_variable();
       }
      }
  </code></pre>
  
  <p>output is this :-</p>
  
  <p>please click on the link to see the output :-
  <a href="https://i.stack.imgur.com/pWhvT.png" rel="nofollow noreferrer">here instead of 8 ten times i needed 10 different values </a></p>