title: Random choices of two values
body: <p>In my algorithm I have two values that I need to choose at random but each one has to be chosen a predetermined number of times.</p>
  
  <p>So far my solution is to put the choices into a vector the correct number of times and then shuffle it. In C++:</p>
  
  <pre><code>// Example choices (can be any positive int)
  int choice1 = 3; 
  int choice2 = 4;
  
  int number_of_choice1s = 5;
  int number_of_choice2s = 1;
  
  std::vector&lt;int&gt; choices;
  for(int i = 0; i &lt; number_of_choice1s; ++i) choices.push_back(choice1);
  for(int i = 0; i &lt; number_of_choice2s; ++i) choices.push_back(choice2);
  std::random_shuffle(choices.begin(), choices.end());
  </code></pre>
  
  <p>Then I keep an iterator to <code>choices</code> and whenever I need a new one I increase the iterator and grab that value.</p>
  
  <p>This works but it seems like there might be a more efficient way. Since I always know how many of each value I'll use I'm wondering if there is a more algorithmic way to go about doing this, rather than just storing the values.</p>