I made it for fun, but I'd love suggestions on how I can improve it in any way. Thanks, love you.
I made a screen recording of it: https://n0ssc.com/wp-content/uploads/2025/08/prime-doublespe...
Now when you take a vertical pattern like you see with column width=10 and add one more to the column size (so make it 11) the pattern is now offset by one pixel on each row. This makes the vertical pattern render diagonally as each row is offset by a pixel.
So you get the patterns going between vertical and diagonal. This can get really interesting when you have a bunch of composite numbers in a row. Each composite number has it's own vertical pattern as described above. So 435 has gaps every 3rd and 5th number (and for other factors) since those will be multiple of 3 or 5. Now the next number, 436 rotates this pattern 45degrees since it offsets each row by 1 pixel. But.. 436 has it's own patterns, eg. every second number is a multiple of 2 when offset from 436 since 436 is even. So it has it's own vertical patterns but also shows the diagonals from gaps in 435.
Anyway these well understood gaps in primality give a galaxy appearance for this simple reason. You're seeing well understood vertical patterns shifting to render diagonally with new vertical patterns from alignment on the next number and repeat.
..... ...... ...... .... .. .. ......
.. .. .. .. .. .. ... .. ..
.. .. .. ... .. .. .. .. .. ..
..... ...... ...... .. .. .. .. .. ...
..... ... .. .. .. .. ... .. ..
.. .. .. .. .. .. .. ... ..
...... .. .. .. .... .. .. .....
to show up, until I realized I've been coding too much today.https://lemire.me/blog/2017/09/18/visiting-all-values-in-an-...
It has better avalanching compared to indexing by `(i * prime) % n`, but at the tradeoff of `n` being restricted to powers of 2.
The blog post uses "random" in quotations as well in its title.
I call it O(1) because the ordering is fully determined just by choosing an arbitrary prime number. It's constant time to "reorder" the elements and also constant time to get the i'th element in the permutation. This is in contrast to something like the the Fisher-Yates shuffle which permutes the elements in O(n) time.
It will sound horrible. IIRC if you know music and choose only 4 notes correctly, even random notes may not sound too bad. So perhaps the version with 88/12*4 columns may be better.
For all integers n ≥ 0, the ranges [243 + (n * 546)] to [249 + (n * 546)] inclusive appear to contain no prime numbers. Same with the ranges [297 + (n * 546)] to [303 + (n * 546)].
For both sets of ranges, the minimum gap between the closest neighbouring primes appears to be at least 10 (in decimal). Does anyone know of a number-theoretic explanation for this kind of pattern?
In a similar way 210=2*3*7*5 also gives wide empty columns (if you ignore ignore first row where 2,3,5,7 themselves are primes)
It helps if you think of it in terms of where the non primes are located instead of where the primes are. Multiples of 2, 3, 5 form a very regular pattern. Wrap it around in a grid and you get straight lines which are either straight vertical or slightly shifted depending on the divisors of width. Stack a couple of repetitive patterns and you still get a repetitive pattern. If the positions which are not primes form a regular pattern, the inverted image also forms recognizable pattern. Of course the primes don't form perfectly regular pattern and but most the visible repetition are result of small prime multiples.
546n + 242 is always even
546n + 243 is always divisible by 3
546n + 244 is always even
546n + 255 is always divisible by 7.
Etc.
It's similar to how in base 10 you never see a prime ending in 0,2,4,6,8 or 5 since those numbers are clearly divisible by 2 or 5. In 546's case you have a lot of factors so even more gaps.
You also get the pattern appearing again since the number is even and the non-even factors repeat their pattern starting from the halfway point.
To finish it off (skipping even numbers)...
546n + 247 is always divisible by 13.
546n + 249 is always divisible by 3.
In this case you're seeing the extension of this to include multiples of 3. That is, all prime numbers above 6 are of the form 6n+1 or 6n+5, all other numbers are either divisible by 2 or 3.
You can extend these patterns. Whenever you have a composite number you'll get periodic points where factors are known. Eg. to extend it one step further you could say all prime numbers above 30 are of the form 30n + [1,7,11,13,17,19,23,29], all others are divisible by 2, 3 or 5.
From this you can also quickly iterate towards to the prime number formula for the frequency of primes. eg. Only half of numbers above 2 can be prime (1/2), the rest are multiples of 2. Over 6 you have half of two thirds of numbers that can possibly be prime, the rest are multiples of 2 or 3. Over 30 only 1/2 x 2/3 x 4/5 could possibly be prime. etc. This converges to the prime number theorem!
Anyway if anyone ever expresses amazement that's good to see but mathematically it's well known. Prime numbers have patterns in their frequency, specifically where there's period multiples of factors there can't possibly be primes. It's the basis for prime number theory and patterns in primes have been known since Erasthosenes was back in BC times. So if you see a pattern here just remember that the pattern comes from looking at a period of a composite number and within that composite number there's guaranteed periodic gaps in primes where the factors of that number repeat.
This btw is something mathematicians deal with a lot. People seem to think prime numbers have no patterns and any view of them that reveals patterns is a surprising which is a weird misconception. Prime numbers absolutely have patterns. It's the basis for prime number theory.
If n is prime and n > 3, then n ≡ 1 (mod 6) or n ≡ 5 (mod 6).
Or more succinctly:
n ≡ ±1 (mod 6).
So when the total number of columns is a multiple of 6, all the primes greater than 3 line up on the nth columns for n = 1, 5, 7, 11, etc.
The numbered values are editable inputs. You can click into them and type in the amount you’d like. If you couldn’t tell they were editable inputs, that’s valuable feedback! I’ll redesign them to make it more obvious that you can do so, and don’t have to just click the +/- buttons.
Check out 431 columns - this yields no obvious persistent patterns.
It's fun seeing all these patterns. I did some edit. I was thinking that skipping over numbers divisible by 2 and 5 will get rid of most visible gaps, but they keep emerging.