A recent discovery, quoted from   Quantamagazine   (March 13, 2016):

     Two mathematicians have uncovered a simple, previously unnoticed property of 
     prime numbers — those numbers that are divisible only by 1 and themselves.     
     Prime numbers, it seems, have decided preferences about the final digits of    
     the primes that immediately follow them.  

and

     This conspiracy among prime numbers seems, at first glance, to violate a     
     longstanding assumption in number theory:  that prime numbers behave much    
     like random numbers. 

                            ─── (original authors from Stanford University):      
                            ─── Kannan Soundararajan  and  Robert Lemke Oliver    



The task is to check this assertion, modulo 10.

Lets call    i -> j    a transition if    i    is the last decimal digit of a prime, and    j    the last decimal digit of the following prime.



Task

Considering the first one million primes.   Count, for any pair of successive primes, the number of transitions    i -> j    and print them along with their relative frequency, sorted by    i .

You can see that, for a given    i ,   frequencies are not evenly distributed.



Observation

(Modulo 10),   primes whose last digit is   9   "prefer"   the digit   1   to the digit   9,   as its following prime.



Extra credit

Do the same for one hundred million primes.



Example for 10,000 primes

10000 first primes. Transitions prime % 10 → next-prime % 10.
1 → 1 count:        365 frequency: 3.65 %
1 → 3 count:        833 frequency: 8.33 %
1 → 7 count:        889 frequency: 8.89 %
1 → 9 count:        397 frequency: 3.97 %
2 → 3 count:          1 frequency: 0.01 %
3 → 1 count:        529 frequency: 5.29 %
3 → 3 count:        324 frequency: 3.24 %
3 → 5 count:          1 frequency: 0.01 %
3 → 7 count:        754 frequency: 7.54 %
3 → 9 count:        907 frequency: 9.07 %
5 → 7 count:          1 frequency: 0.01 %
7 → 1 count:        655 frequency: 6.55 %
7 → 3 count:        722 frequency: 7.22 %
7 → 7 count:        323 frequency: 3.23 %
7 → 9 count:        808 frequency: 8.08 %
9 → 1 count:        935 frequency: 9.35 %
9 → 3 count:        635 frequency: 6.35 %
9 → 7 count:        541 frequency: 5.41 %
9 → 9 count:        379 frequency: 3.79 % 



/*REXX pgm shows a table of what last digit follows the previous last digit for N primes*/
parse arg N .                                    /*N:  the number of primes to be genned*/
if N=='' | N==","  then N= 1000000               /*Not specified?  Then use the default.*/
Np= N+1;                w= length(N-1)           /*W:  width used for formatting output.*/
H= N* (2**max(4, (w%2+1) ) )                     /*used as a rough limit for the sieve. */
@.= .                                            /*assume all numbers are prime (so far)*/
#= 1                                             /*primes found so far {assume prime 2}.*/
     do j=3  by 2;     if @.j==''  then iterate  /*Is composite?  Then skip this number.*/
     #= #+1                                      /*bump the prime number counter.       */
             do m=j*j  to H  by j+j;    @.m=     /*strike odd multiples as composite.   */
             end   /*m*/
     if #==Np  then leave                        /*Enough primes?   Then done with gen. */
     end   /*j*/                                 /* [↑]  gen using Eratosthenes' sieve. */
!.= 0                                            /*initialize all the frequency counters*/
say 'For '   N   " primes used in this study:"   /*show hdr information about this run. */
r= 2                                             /*the last digit of the very 1st prime.*/
#= 1                                             /*the number of primes looked at so far*/
     do i=3  by 2;     if @.i==''  then iterate  /*This number composite? Then ignore it*/
     #= # + 1;         parse var  i   ''  -1  x  /*bump prime counter; get its last dig.*/
     !.r.x= !.r.x +1;  r= x                      /*bump the last digit counter for prev.*/
     if #==Np  then leave                        /*Done?   Then leave this  DO  loop.   */
     end   /*i*/                                 /* [↑]  examine almost all odd numbers.*/
say                                              /* [↓]  display the results to the term*/
     do    d=1  for 9; if d//2 | d==2  then say  /*display a blank line (if appropriate)*/
        do f=1  for 9; if !.d.f==0  then iterate /*don't show if the count is zero.     */
        say 'digit '      d      "──►"       f        ' has a count of: ',
             right(!.d.f, w)",  frequency of:"   right(format(!.d.f / N*100, , 4)'%.', 10)
        end   /*f*/
     end      /*d*/                              /*stick a fork in it,  we're all done. */