// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; public class BadRng3 { public const int N = 50000; public const int K = 10; public static void Main(string[] args) { Random rng = new Random(); int[] one = new int[K]; int[,] two = new int[K,K]; int[] a = new int[N]; for(int i = 0; i < N; i++) { a[i] = (rng.Next(K) + rng.Next(K)) / 2; // average of two random numbers 0..9 } for(int i = 0; i < N; i++) { one[a[i]]++; } int last = a[0]; for(int i = 1; i < N; i++) { two[last,a[i]]++; last = a[i]; } for(int i = 0; i < K; i++) { Console.WriteLine(one[i]); } for(int i = 0; i < K; i++) { for(int j = 0; j < K; j++) { Console.Write(" " + two[i,j]); } Console.WriteLine(); } } }