## Using Prime Numbers to Generate Backgrounds 180

bpeh123 pointed out an article about generating organically tiled backgrounds inspired by the life cycle of cicadas. The trick is to overlay multiple background tiles with prime widths thus generating a series that does not repeat for a sufficiently long period. This introduces a seeming irregularity and makes the background appear much more natural.

## Fuck you slashdot (Score:2, Informative)

Why can I only check Post Anonymously when I post a new comment but not a reply? Also, it would be kinda cool if I could click on fucking links again without having to triple right click and then open in a new window.

## 1 is the loneliest (non-prime) number (Score:0, Informative)

From TFA:

FAIL. 1 is not prime.

## Re:OMG Sicadas are illuminati (Score:4, Informative)

Yes, some characters do. The Slashdot Janitors have decreed that only 7-bit ASCII can be used on the site and everything else should be presented in as broken a way as possible.

Because obviously, we're geeks so we're all using 30-year-old ADM3A terminals.

## 1 is a prime. (Score:2, Informative)

There are two schools of thought, one considers 1 to be a prime (since its divisors are "1" and itself) the other school of thought doesn't. Some proofs work nicer if 1 is considered to be a prime, some proofs don't.

So it's just a matter of opinion.

## Re:1 is the loneliest (non-prime) number (Score:3, Informative)

Primes have, by definition, exactly two factors. 1 has only one: 1.

Of course, you

coulddefine them differently, and a hundred years ago, 1 indeed was considered a prime. But the definition excluding 1 has turned out to be much more useful (because almost everywhere you use primes you'd have to add "except 1" otherwise), therefore 1 is no longer considered prime.## Re:Ow. That made my brain hurt. (Score:5, Informative)

The point isn't randomness, the point is unwanted harmonics in pseudo-random patterns. These unwanted harmonics cause regular repetitions in the pattern that make it seem predictable and non-random. Prime numbers are the basis by which a simple PRNG (pseudo-random number generator) generates seemingly-random data that doesn't repeat in any predictable manner. By overlapping two or more sequences with prime lengths, the length of the harmonic is maximized. That means the sequence goes longer before repeating itself. Sequences with non-prime lengths short-circuit the cycle.

For instance, overlapping three sequences of length 7, 11, and 13 forms the following pattern:

http://tinyurl.com/3wserj7 [tinyurl.com]

At a glance, the pattern looks fairly random and non-repeating; however if you look more closely you see that the vertical bands of color are repeating very regularly within the pattern. But, since their periodicity is prime, the pattern as a whole doesn't appear to repeat itself. Using alpha and larger 2-dimensional tiles you can create even more complex and random-seeming patterns.

The life cycle of cicadas is similar in that the overlapping cycles tend to cause a seemingly-random pattern of years with lots of cicadas and few cicadas, such that the life cycle of their predators is less likely to hit a bunch of good cicada years in a row and seriously harm the population of them.

## Re:1 is a prime. (Score:3, Informative)

A lot of proofs in recursion / computability theory actually depend on the fact that one is not a prime number. More specifically, they depend on the property of numbers that is called unique factorisation into primes, a very important theorem in mathematics that is a corner stone for many proofs in a variety of mathematical disciplines. If you count 1 as a prime number, this theorem does not hold, with all the consequences that you might suspect it entails.

Just sayin'. 1 is not a prime number.

## Re:1 is a prime. (Score:5, Informative)

This is in fact true.

The best reason for leaving one out of the prime number set is because it enables you to state the prime number theorem more succinctly:

Every integer n>1 has a unique factorisation as a product of primes (Prime factorisation)If one was prime, then the factorisation would not be unique. For example 6=2.3, but if 1 was an allowed prime then 6=1.2.3=1.1.2.3=1.1.1.2.3= .... 1^n .2.3. So it's preferred to leave one out.

There are other reasons, but the prime number theorem is perhaps the best one.

## Re:Congratulations... (Score:5, Informative)

This is very much

notlike Perlin noise, because Perlin noise uses octaves (doubles in frequency). Octaves are harmonic with each other by definition. This uses primes, specifically to cause the harmonics to occur as far apart as possible. Using octaves in this way would cause very repetitive-seeming patterns because the maximum size of your pattern would be defined as the size of your largest sequence, and all of the shorter sequences would tile into it in a neat checkerboard.Perlin noise requires

infinitesequences of pseudo-random numbers and would be extremely ill-suited to using short repeating sequences. This is specifically designed to minimize the length of the sequences you use without causing obvious repetitions in the pattern by using sequences of prime length (since your "sequence" is a PNG, if it's too large it takes a long time to load).