Visual Prime Patterns & Spreads

Prime Distribution & Ulam Spiral

Explore visual patterns, diagonal lines, and spiral shapes to see how prime numbers are spread out.

Total Integers (N²) 2,601
Primes Found π(N²) 374
Actual Share of Primes 14.38%
Formula Estimate 1/ln(N²) 12.72%
01

Round Spiral (Sacks) vs. Square Spiral (Ulam)

In 1994, software engineer Robert Sacks made a round version of Ulam’s square grid spiral. Instead of turning sharp square corners, every number n steps outward smoothly along a circle:

Round Spiral Layout: Distance from center r = √n,   Turn angle θ = 2π × √n (one full loop per square number)

With this layout, all square numbers (1², 2², 3², 4²…) sit cleanly on the straight line pointing right. Meanwhile, prime-rich formulas like Euler’s n² + n + 41 turn into smooth curved arcs instead of broken diagonal lines!

Interactive Sacks Spiral (N = 1,000)
Green dots = Primes | Faint rings = √n distance from center. Euler curve highlights in amber.
Interactive Tool Formula Tester

02. Custom Prime-Making Formula Checker

Try any squared math formula f(n) = a·n² + b·n + c below to check its test score (D = b² − 4ac) and see how many prime numbers it makes from n = 0 to 39:

03. 20 Famous Prime-Making Formulas

Explore 20 well-known formulas behind spiral lines and prime runs. Click “Try It” to load any rule:

Formula f(n) Score D Primes (n ≤ 39) Success % Why It’s Known Action
n² + n + 41 -163 40 / 40 100.0% Euler's famous rule; 40 primes in a row
n² - n + 41 -163 40 / 40 100.0% Shifted Euler rule; 41 primes for n = 1..41
n² + n + 17 -67 16 / 40 40.0% Euler lucky number 17; 16 primes in a row
n² + n + 11 -43 10 / 40 25.0% Euler lucky number 11; 10 primes in a row
n² + n + 5 -19 4 / 40 10.0% Euler lucky number 5; 4 primes in a row
n² + n + 3 -11 2 / 40 5.0% Euler lucky number 3; 2 primes in a row
n² - 79n + 1601 -163 40 / 40 100.0% Shifted rule making 80 primes in a row (with repeats)
2n² + 29 -232 29 / 40 72.5% 29 consecutive primes for n = 0..28
4n² - 2n + 41 -652 33 / 40 82.5% Clear dark diagonal on the Ulam spiral
4n² + 4n + 59 -928 27 / 40 67.5% Strong prime diagonal line on Ulam grid
4n² + 2n + 41 -652 31 / 40 77.5% Matching Ulam diagonal line
6n² + 6n + 31 -708 29 / 40 72.5% High-yield prime formula (72.5%)
2n² - 2n + 19 -148 19 / 40 47.5% Legendre prime-rich formula
3n² + 3n + 23 -267 23 / 40 57.5% Produces 23 primes out of the first 40 tries
n² + 2 -8 14 / 40 35.0% Simple square-plus-2 rule
4n² + 1 -16 16 / 40 40.0% Odd square rule producing 16 primes
n² + 1 -4 19 / 40 47.5% Famous unsolved question: does it make infinitely many primes?
2n² + 11 -88 20 / 40 50.0% Hits primes on half of the first 40 inputs
3n² + 5 -60 15 / 40 37.5% Alternate prime-rich square rule
n² + n + 1 -3 8 / 40 20.0% Classic triangle-number helper rule
04

How Primes Thin Out as Numbers Grow: 1 / ln(x)

Even though prime numbers go on forever, they spread farther apart as numbers get larger. Near any number x, the chance a number is prime is about 1 / ln(x). Slide the scale below to see primes thin out from 10 up to 1 trillion:

Scale x = 10ᵏ: 10⁶ (1,000,000)
10¹ (10) 10⁶ (1M) 10¹² (1 Trillion)
Natural Log ln(x) 13.82
Chance a Number is Prime 7.24%
Average Gap Between Primes ~14 numbers
Around 1,000,000, roughly 1 in every 14 numbers is prime. In a stretch of 100 numbers near 1 million, you can expect roughly 7 prime numbers.
05

Random Walk: Primes vs. Random Chance

In 1936, mathematician Harald Cramér noticed that primes spread out similarly to coin flips. Click “Simulate New Walk” to compare how actual primes grow compared to 3 random walks:

Comparison for numbers 3 to 500
Actual Primes Random Walks

06. Step-by-Step Examples

Example 1: Euler's n² + n + 41 40 Primes in a Row

Starting at n = 0 gives 41. At n = 1 it gives 43, and at n = 2 it gives 47. It continues giving prime numbers all the way up to n = 39 (1,601), before finally giving 41 × 41 at n = 40.

40 consecutive primes
Example 2: Sacks Smooth Spiral Straight Line of Squares

When numbers wrap around a smooth round spiral, square numbers like 4, 9, 16, and 25 all land in a neat straight line, making curves of prime numbers easy to follow.

Square numbers line up neatly
Example 3: Ulam Main Diagonal Diagonal Line

Diagonal cells in the Ulam grid follow formulas like 4k² − 2k + 41. Because these formulas produce many primes, clear dark diagonal stripes cut across the grid.

Visible dark diagonal stripe
Example 4: Natural Prime Waves Natural Spread

Prime counts closely follow mathematical predictions, but like waves on water, they naturally swing slightly above and slightly below the estimated line as numbers grow.

Curves gently above and below the estimate

07. Real-World Applications & Uses

Spotting Flaws in Random Numbers

When computer random number generators are plotted on a spiral grid, bad generators create clear stripes, revealing flaws that can make security keys predictable.

Patterns in Nature & Crystals

The way primes are spaced out closely resembles the intricate, non-repeating crystal patterns found in natural minerals and physics.

Physics & Energy Levels

Physicists have found that the spacings between prime numbers closely match the energy levels found in heavy atoms, linking prime math directly to nature.

Plant Spirals & Sunflower Seeds

Spiral number patterns appear naturally in sunflower seed heads and pinecones, where spiral packing helps plants fit the maximum number of seeds without crowding.

Related Prime Tools

Frequently Asked Questions

What is the Ulam spiral and how was it discovered?

The Ulam spiral is a visual way to plot numbers in a square spiral, discovered in 1963 by mathematician Stanislaw Ulam. When you mark all the prime numbers on the grid, surprising diagonal lines appear instead of random dots.

Why do prime numbers form diagonal lines on the Ulam spiral?

Diagonal lines on the spiral match simple math formulas (like 4n² + bn + c). Certain formulas, such as Euler's famous n² + n + 41, produce lots of prime numbers, creating visible lines on the grid.

What is the Sacks spiral and how is it different?

The Sacks spiral plots numbers along a smooth, round spiral instead of a square box. Perfect squares line up neatly along a straight horizontal line, causing prime clusters to appear as smooth curves.

What are Euler's Lucky Numbers?

Mathematician Leonhard Euler discovered that the formula n² + n + 41 produces 40 prime numbers in a row (for n = 0 to 39). Mathematicians later proved there are only six special numbers like 41 (2, 3, 5, 11, 17, and 41) that produce long runs of primes.

How does the percentage of prime numbers change as numbers grow?

As numbers get larger, prime numbers appear less often. For example, about 1 in 7 numbers around 1,000 is prime, but around 1,000,000 only about 1 in 14 is prime.

Can prime numbers be modeled like coin flips?

Even though prime numbers follow exact math rules, their gaps and spreads closely match what happens if you flip a weighted coin with probability 1 / ln(n).

Can math formulas predict prime numbers?

While no single algebraic formula can produce only prime numbers forever, mathematicians have shown that certain formulas produce unusually rich clusters of prime numbers.