title: Python: simulate tossing a die until all values have appeared at least once
body: <p>I want to sample from a list until all elements have appeared at least once. We can use tossing a die as an example. A die has six sides: 1 through 6. I keep tossing it until I see all six values at least once, then I stop. Here is my function.</p>
  <pre><code>import numpy as np
  
  def sample_until_all(all_values):
      sampled_vals = np.empty(0)
      while True:
          cur_val = np.random.choice(all_values, 1)
          sampled_vals = np.append(sampled_vals, cur_val[0])        
          if set(all_values) == set(sampled_vals):
              return(len(sampled_vals))
          
  sample_until_all(range(6))
  </code></pre>
  <p><code>cur_val</code> is the value from the current toss. I keep all sampled values in <code>sampled_vals</code> using <code>np.append</code>, and I check if it contains all possible values after each toss using <code>set(all_values) == set(sampled_vals)</code>. It works but not efficiently (I believe). Any ideas how to make it faster? Thanks.</p>
  <p>I just use this as a toy example. The actual list I need is much larger than just 6 values.</p>