title: Extract random index from a fixed array c++
body: <p>Lets say that I have an array containing 52 elements. How would one go about to extract a random index from this array and assign it to a new variable? I have created a function that is supposed to shuffle some cards but I want to "deal" the cards by selecting a totally random index from this already shuffled array. I just need help with the extraction part.</p>
  
  <pre><code>int random(int cards[52])
  {
      for (int i = 0; i &lt; 52; i++)
      {
          cards[i]= i; // Fill the array
      }
  
      for (int i = 0; i &lt; (52-1); i++) //Shuffle the elements randomly.
      {
          int r = i + (rand() % (52-1));
          int temp = cards[i]; cards[r]; cards[r] = temp;
      }
  
      return (cards[52]);
  }
  </code></pre>