/* Collection of code snippets by Arne Vajhøj */
/* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define N 50000
#define K 10

int main()
{
    int i, j, last, one[K], two[K][K], a[N];
    for(i = 0; i < N; i++)
    {
        srand(time(NULL)); /* <---- initialize for every number */
        a[i] = rand() % K;
    }
    for(i = 0; i < K; i++) one[i] = 0;
    for(i = 0; i < N; i++)
    {
        one[a[i]]++;
    }
    for(i = 0; i < K; i++) for(j = 0; j < K; j++) two[i][j] = 0;
    last = a[0];
    for(i = 1; i < N; i++)
    {
        two[last][a[i]]++;
        last = a[i];
    }
    for(int i = 0; i < K; i++)
    {
        printf("%d\n", one[i]);
    }
    for(int i = 0; i < K; i++)
    {
        for(int j = 0; j < K; j++)
        {
            printf(" %d", two[i][j]);
        }
        printf("\n");
    }
    return 0;
}
