Mathematicians are pretty obsessed with prime numbers - those elusive integers that can only be divided by one and themselves. If they're not creating cool artworks with them or finding them in nature, they're using computers to discover increasingly larger primes.

But now a group of researchers has found a strange property of primes that's never been seen before, and it violates one of the fundamental assumptions about how they behave - the idea that, for the most part, they occur totally randomly across integers.

The pattern isn't actually found within the primes themselves, but rather the final digit of the prime number that comes directly after them - which the mathematicians have shown isn't as random as you'd expect, and that's a pretty big deal for mathematicians.

"We’ve been studying primes for a long time, and no one spotted this before," Andrew Granville, a number theorist at the University of Montreal who wasn't involved in the study, told Quanta magazine. "It’s crazy."

So what are we talking about here? Our current understanding of primes suggests that, over a big enough sample, they should occur randomly, and shouldn't be influenced by the prime number that comes before or after them.

But that's not what Kannan Soundararajan and Robert Lemke Oliver from Stanford University in California found.

They performed a randomness check on the first 100 million primes and found that a prime ending in 1 was followed by another prime ending in 1 only 18.5 percent of the time - a far cry from the 25 percent you'd expect given that primes greater than five can only end in one of four digits: 1, 3, 7, or 9.

Furthermore, the chance of a prime ending in 1 being followed by a prime ending in 3 or 7 was roughly 30 percent, but for 9 it was only 22 percent.

In other words, the primes "really hate to repeat themselves", said Lemke Oliver.

The obvious explanation for this is the fact that numbers have to cycle through all the other digits before they get back to the same ending. "For example, 43 is followed by 47, 49, and 51 before it hits 53, and one of those numbers, 47, is prime," writes Jacob Aron for New Scientist.

But this doesn't explain the magnitude of the bias the team found, or why primes ending in 3 seemed to like being followed by primes ending in 9 more than 1 or 7. Even when they expanded their sample and examined the first few trillion prime numbers, the mathematicians found that - even though the bias gradually falls more in line with randomness - it still persists.

"I was very surprised," James Maynard from the University of Oxford told New Scientist. "I somehow needed to see it for myself to really believe it," he says, admitting that he ran back to his office and performed the calculations himself after hearing about the work.

So what's going on?

According to Soundararajan and Lemke Oliver, the pattern can be explained by something called the k-tuple conjecture - an old but unproven idea that describes how often pairs, triples, and larger sets of primes will make an appearance, and how close together these should occur.

Essentially, the k-tuple conjecture proposes that groups of primes don't appear all that randomly, and Soundararajan and Lemke Oliver showed that this prediction could accurately explain the last-digit pattern they found.

Maynard agrees with this outcome, which has been published on pre-press site ArXiv.org, and hopes that it'll be further evidence that primes do contain patterns, even if we can't always see them.

"Mathematicians go around assuming primes are random, and 99 percent of the time this is correct, but you need to remember the 1 percent of the time it isn’t," said Maynard. "If anything, I view this result as even more confirmation of the k-tuple conjecture."

Despite the fact that it's pretty exciting work, the newly spotted pattern doesn't really provide many practical answers for number theorists - for example, there's still the twin-prime conjecture and the Riemann hypothesis that need to be resolved.

The study also hasn't been peer reviewed as yet, so we need to take it with a grain of salt, but it's been placed on ArXiv so that other mathematicians can look over the work and add their own ideas and suggestions.

According to Granville, the discovery takes us one step closer to properly understanding the enigmatic primes. "Every little bit helps ... I can’t believe anyone in the world would have guessed this," he told New Scientist. "You could wonder, what else have we missed about the primes?"