// 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 BadRng1 { public const int N = 50000; public const int K = 10; public static readonly Random rng = new Random(); // <---- initialize once public static void Main(string[] args) { 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); } 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(); } } }