How to generate a stream of *unique* random numbers in Go using the standard library
<p>How can I generate a stream of <strong>unique</strong> random number in Go?</p>
<p>I want to guarantee there are no duplicate values in array <code>a</code> using <code>math/rand</code> and/or standard Go library utilities.</p>
<pre><code>func RandomNumberGenerator() *rand.Rand {
    s1 := rand.NewSource(time.Now().UnixNano())
    r1 := rand.New(s1)          
    return r1
}
rng := RandomNumberGenerator()    
N := 10000
for i := 0; i &lt; N; i++ {
    a[i] = rng.Int()
}
</code></pre>
<hr />
<p>There are questions and solutions on how to generate a series of random number in Go, for example, <a href="https://stackoverflow.com/questions/6181260/generating-random-numbers-in-go">here</a>.</p>
<p>But I would like to generate a series of random numbers that does not duplicate previous values. Is there a standard/recommended way to achieve this in Go?</p>
<p>My guess is to (1) use permutation or to (2) keep track of previously generated numbers and regenerate a value if it's been generated before.</p>
<p>But solution (1) sounds like  overkill if I only want a few number and (2) sounds very time consuming if I end up generating a long series of random numbers due to collision, and I guess it's also very memory-consuming.</p>
<hr />
<p><strong>Use Case</strong>: To benchmark a Go program with 10K, 100K, 1M pseudo-random number that has no duplicates.</p>