When random is not actually random enough
What happened
There is a common pattern you see pop up in codebases everywhere that many of us have written: given a set of objects, pick one at random. Every object should have the same chance of being picked. A rather simple and direct solution is to pick a big random number, then clamp that number to the number of choices by modulo:
Summary assembled by rule from the sources below
Why it's spreading
Timeline
- First appeared on Hacker NewsHacker News
- Discussion started on LobstersLobsters