Numpy’s random choice in GoLang
<p>Recently I’ve assisted with implementing some logic in Java that could easily be achieved with a single call of Numpy’s <code>random.choice</code>. It ended up being one of those tasks that allow looking into things you’re using every day but never have time to fully understand how they work. Also for quite some time I wanted to start learning Go, so why not kill two birds with one stone and reimplement <code>random.choice</code> once again this time in Go?</p>
<p><code>random.choice</code> allows us to sample N elements from a provided collection according to the specified probabilities. Importantly (for the use case that motivated this work), it allows us to sample these elements without replacements. I.e. if an element of collection was already sampled it won’t be sampled again. For example, if we have a collection [A, B, C] with associated probabilities [0.1, 0.7, 0.2] and we want to sample 3 elements without replacements, most of the time we’ll get [B, C, A] as an output. If we sample with replacement, the expected output would be [B, B, B].</p>
<p><a href="https://towardsdatascience.com/numpys-random-choice-in-go-d65bc2838191"><strong>Click Here</strong></a></p>