liveBook · Manning

Uniform distribution

As explained in Statistics Every Programmer Needs

A continuous uniform distribution assigns equal probability density across a continuous interval of possible values.

A uniform distribution assigns equal likelihood to its possible outcomes. For a finite set of discrete values, each value has probability 1 divided by the number of values. A fair six-sided die therefore gives each face probability 1/6. This discrete case is distinct from a continuous uniform distribution, which is not developed here. section 3.1.3

To use a discrete uniform model:

  • Specify the finite set of possible values and check that each is equally likely. Their probabilities must sum to 1. section 3.1.3
  • For consecutive integers from a through b, count b − a + 1 outcomes; each has probability 1/(b − a + 1). A plot of their probabilities is flat, or rectangular. section 3.1.3
  • Keep equal likelihood within one draw separate from independence between draws. A previous die roll does not change the probabilities on the next roll. section 3.3.2

Generate and check a flat-digit baseline

In Python, `np.random.randint(1, 10, size=1000)` generates 1,000 integers from 1 through 9. Group the results by value and count them to inspect the observed frequencies. Each digit has the same modeled probability, but the counts need not match: one run produced counts ranging from 101 to 130, rather than exactly 111 per digit. Treat the flat pattern as an expectation, not a guarantee for a finite sample. section 12.3.1 section 12.3.3

Figure 12.2 A uniform distribution of 1,000 records on top and a random distribution of 1,000 records on the bottom. Many numeric data sets take on one of these two probability distributions. In a Benford distribution, 1s, 2s, and 3s represent more than 60% of the occurrences, but in both these distributions, those digits represent barely 30% of the occurrences.
figure

Compare the roughly flat digit counts with Benford’s leading-digit pattern, where smaller digits occur more often. The contrast helps test whether a uniform baseline is appropriate for numeric data. section 12.3.3

How Statistics Every Programmer Needs covers it

How deep it goes
Defines the discrete case, calculates its per-value probability, and demonstrates sampling; stops short of developing continuous uniform density.
Examples
Uses fair dice, coin flips, card selection, and 1,000 generated integers from 1 through 9.
What it assumes
Builds on random variables and basic probability while defining the discrete uniform case before using Python to generate outcomes.
What you can do after
Apply it via NumPy to generate discrete uniform samples, count outcomes, and interpret departures from equal observed frequencies.
How it connects
Connects discrete random variables, probability mass functions, independent trials, and Benford’s law.

Also explained in

Compare how 9 books explain uniform distribution →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.