← Thursday, October 8, 2026Performance & OSDeep dive

Modulo can skew random selection when the choice count does not divide the range

ersc.io 8 min read Editor score 7/10

Taking a random integer modulo the number of choices does not preserve a uniform distribution when the range is not evenly divisible. Engineers writing sampling or selection code should account for this bias rather than assume each outcome is equally likely.

What
Using modulo to map a uniformly random number to a choice count can make some choices more likely than others.
How
With 10 equally likely inputs mapped to 3 choices, modulo gives one choice 40% probability and the other two 30% each.
Why it matters
Engineers implementing random selection need to account for distribution bias; the excerpt recommends a `random_between` function for uniform ranges.

Discussion

Discussion is not switched on yet. Use Note above to keep your own thoughts on this story.

Headline, summary, brief and diagram are written by a model from the source's own text; the link, byline and numbers come from the source. Read the original before relying on a claim.

Your note

Private to you. Stored in this browser, and synced to your account when you are signed in.