title: Random in Rock-Paper-Scissors game in C++
body: <p>This is the first piece of code I wrote on my own. I have a program that uses 2 different functions to compute who would win in a game of Rock Paper Scissors but it is giving me the same output everytime.</p>
  
  <p>I think there is a problem with the random function as it not generating the random numbers but I am unable to find out the problem. </p>
  
  <p>Any help would be greatly appreciated. </p>
  
  <pre><code>struct RPS //Rock Paper Scissors {
      unsigned seed = time(0);
      int RPS1 = rand() % 3; // Random Number Generator for Player 1
      int RPS2 = rand() % 3; // Random Number Generator for Player 2
  };
  
  int Player_1(int Rock = 0, int Paper = 1, int Scissors = 2) {
      RPS get; // Calls the number from the "struck RPS" data structure
      if (get.RPS1 == 0) {
          cout &lt;&lt; "Player 1 selected Rock" &lt;&lt; endl;
          return Rock;
          }
      else if (get.RPS1 == 1){
          cout &lt;&lt; "Player 1 selected Paper" &lt;&lt; endl;
          return Paper;
      }
      else{
          cout &lt;&lt; "Player 1 selected Scissors" &lt;&lt; endl;
          return Scissors;
      }
  }
  
  int Player_2(int Rock = 0, int Paper = 1, int Scissors = 2) {
      RPS get; // Calls the number from the "struck RPS" data structure
      if (get.RPS2 == 0) {
          cout &lt;&lt; "Player 2 selected Rock" &lt;&lt; endl;
          return Rock;
      }
      else if (get.RPS2 == 1) {
          cout &lt;&lt; "Player 2 selected Paper" &lt;&lt; endl;
          return Paper;
      }
      else {
          cout &lt;&lt; "Player 2 selected Scissors" &lt;&lt; endl;
          return Scissors;
      }
  }
  
  int Who_Won(int tie = 0, int Player_1_Won = 1, int Player_2_Won = 2) {
      RPS get; // Calls the number from the "struck RPS" data structure
  
      if ((get.RPS1 == 0 &amp;&amp; get.RPS2 == 2)
          || (get.RPS1 == 1 &amp;&amp; get.RPS2 == 0)
          || (get.RPS1 == 2 &amp;&amp; get.RPS2 == 1)) {
          cout &lt;&lt; "Player 1 Won" &lt;&lt; endl;
          return Player_1_Won;
      }
  
      else if ((get.RPS2 == 0 &amp;&amp; get.RPS1 == 2)
          || (get.RPS2 == 1 &amp;&amp; get.RPS1 == 0)
          || (get.RPS2 == 2 &amp;&amp; get.RPS1 == 1)) {
          cout &lt;&lt; "Player 2 Won" &lt;&lt; endl;
          return Player_2_Won;
      }
  
      else {
          cout &lt;&lt; "It's a tie" &lt;&lt; endl;
          return tie;
      }
  }
  
  int main() {
      RPS get; // Calls the number from the "struck RPS" data structure
  
      clock_t begin, end;
      double elapsed_seconds;
  
      // This clock runs the time for player 1.
      begin = clock();
      Player_1(0, 1, 2);
      end = clock();
      cout &lt;&lt; endl;
      elapsed_seconds = double(end - begin) / CLOCKS_PER_SEC;
      cout &lt;&lt; "The time it took to run the player_1 function was: " &lt;&lt; elapsed_seconds &lt;&lt; endl &lt;&lt; endl;
  
      cout &lt;&lt; "************************************************************" &lt;&lt; endl &lt;&lt; endl;
  
      // This clock runs the time for player 2.
      begin = clock();
      Player_2(0, 1, 2);
      end = clock();
      cout &lt;&lt; endl;
      elapsed_seconds = double(end - begin) / CLOCKS_PER_SEC;
      cout &lt;&lt; "The time it took to run the player_2 function was: " &lt;&lt; elapsed_seconds &lt;&lt; endl &lt;&lt; endl;
  
      cout &lt;&lt; "************************************************************" &lt;&lt; endl &lt;&lt; endl;
  
      // Here, we calculate who won
      Who_Won(0, 1, 2);
      cout &lt;&lt; endl;
  
      system("pause");
      return 0;
  }
  </code></pre>