Prime numbers — those that are divisible only by 1 and themselves — aren’t quite as random as mathematicians thought. In particular, they seem to have definite preferences about the final digits of the primes that follow them.

Primes especially dislike following primes with the same final digit as their own. Among the first billion primes, for example, primes ending in 9 follow a prime also ending in 9 only 60 percent as often as they follow a prime ending in 1.

In a paper submitted in March, Kannan Soundararajan of Stanford University and Robert Lemke Oliver of Tufts University showed that the pattern holds among the first 400 billion primes and offered a possible explanation for it. The tendency diminishes as primes get bigger, but only very slowly.

The discovery shocked mathematicians, because a fundamental understanding about prime numbers is that they behave much like random numbers, without orderly patterns in their distribution. The new information shows that this randomness is more complicated than had been believed.