Pimp My IDE / garage dispatchBack to the garage
October 7, 2026 / testing / random selection

Modulo loads one bay heavier.

A uniform random integer does not stay uniform when its source range does not divide cleanly by the number of choices.

Ask for a choice or a range. Do not build one with raw modulo.

Ten states do not split into three equal piles.

EastRiver SourceControl starts with a common shortcut. Draw a uniform integer, then use value % choices to select an item. If the source has ten possible values and the destination has three choices, one choice receives four source values. The others receive three each. The result is 40, 30, and 30 percent instead of equal thirds.[1]

The random generator did its job. The mapping changed the distribution. The bug sits between a low-level number API and the job the application meant to perform.

A random number is raw stock. A random choice is the finished part.

Reject the tail or use the library.

One unbiased mapping accepts the largest prefix of source states that divides evenly by the choice count. It rejects any states left in the tail and draws again. In the ten-state example, values zero through eight form three equal groups. Value nine returns to the hopper.

Application code should usually call the language's range or choice function instead. Python documents uniform integer selection with randrange() and uniform sequence selection with choice(). It also provides choices() when relative weights are intentional.[2] Rust's rand crate provides random_range for one sample and Uniform for repeated sampling between bounds.[3]

Name the distribution in the review.

A reviewer should not have to infer intent from arithmetic. Write whether the selection is uniform or weighted. Name the source API, the destination count, and the test that would expose a heavy bucket. If repeatability matters, record the generator and seed too. A seed can replay the same biased mapping perfectly.

The distributor below makes the mapping visible. It is a finite teaching model. It does not test an actual random generator, prove statistical quality, or select a security-safe API.

Interactive makeover / finite distribution inspector

Randomness distributor

Traditional purpose replaced: a random picker with invisible arithmetic. Better version: native controls expose the source states, output bays, mapping rule, rejected tail, and copyable review card.

Set the feed

This model enumerates a small source range. Every source state is equally likely by definition. It does not sample a generator.

Mapping rule
10
8 states64 states
3
2 choices8 choices
Raw modulo10 source / 3 choices
0A1B2C3A4B5C6A7B8C9A
Bay A4
Bay B3
Bay C3

Raw modulo creates counts of 4, 3, and 3. Bay A receives one extra source state.

Sources read / October 7, 2026

Source log

Open the evidence boundary
  1. EastRiver SourceControl, "When random is not actually random enough". Read October 7, 2026. The post explains modulo bias with a ten-state, three-choice table and recommends expressing the intended distribution directly. It also describes the author's use of weighted choices in deterministic fuzzing.
  2. Python 3.14 random module documentation. Read October 7, 2026. The standard library documents uniform range and sequence selection, weighted choices, generator state, and its separate warning against cryptographic use.
  3. Rust rand 0.10.3 Uniform documentation. Read October 7, 2026. The crate documents bounded uniform sampling, construction cost, random_range for one sample, and implementation caveats.
  4. Hacker News discussion 49983404. Verified through the official item API on October 7, 2026. It was a discovery and reader-response source, not proof of random-number behavior.

Evidence boundary: the finite counts in this page follow directly from enumerating the displayed source states. The page does not inspect a repository, run a statistical test, compare generator quality, or recommend an API for cryptographic work.