title: Making Sure a Number Isn't "Guessed" Twice?
body: <p>I have the following code that sets an initial random number, and random numbers are generated until a random number matches the initial random number - I also record how many guesses it took for this to happen (and then repeat this process many times over - each repetition is called a &quot;game&quot;):</p>
  <pre><code>all_games &lt;- vector(&quot;list&quot;, 100)
  
  for (i in 1:100){
      guess_i = 0
      correct_i = sample(1:100, 1)
      trial_index &lt;- 1  
      while(guess_i != correct_i){
          guess_i = sample(1:100, 1)
          trial_index &lt;- trial_index + 1  
      }
      
      game_results_i &lt;- data.frame(i, trial_index, guess_i, correct_i)
      all_games[[i]] &lt;-  game_results_i
  }
  </code></pre>
  <ul>
  <li>Is it possible to modify this code to ensure that in any game, no number is guessed twice?</li>
  </ul>
  <p>I thought that maybe I could ensure this by keeping track of all the numbers that were guessed in a game, and then removing them from the possible numbers that could be generated in the next turn:</p>
  <pre><code>all_games &lt;- vector(&quot;list&quot;, 100)
  
  guesses_in_a_game &lt;- list()
  all_guesses &lt;- list()
  
  for (i in 1:100){
      guess_i = 0
      correct_i = sample(1:100, 1)
      trial_index &lt;- 1  
      while(guess_i != correct_i){
  
          guess_i = sample(1:100, 1)
           guesses_in_a_game[[i]] = guess_i
          trial_index &lt;- trial_index + 1  
      }
      all_guesses[[i]] &lt;- guess_i
      game_results_i &lt;- data.frame(i, trial_index, guess_i, correct_i)
      all_games[[i]] &lt;-  game_results_i
  } 
  </code></pre>
  <p>But I am not sure how to write the code for this.</p>
  <p>Can someone please help me with this?</p>
  <p>Thank you!</p>