/* 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];
    srand(time(NULL));
    for(i = 0; i < N; i++)
    {
        a[i] = (int)(((rand() % 15) / 15.0) * K);  /* scale random number 0..14 to 0..9 */
    }
    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;
}
