public static void Main() { // 1) Use SuperSillyGenerator to generate a few numbers. Console.WriteLine("Super silly generator in action!"); var ssg = new SuperSillyGenerator(21U); foreach (var x in ssg.Doubles().Take(5)) { Console.WriteLine(x); } Console.WriteLine(); // 2) Use SuperSillyContinuousDistribution to generate a few numbers. Console.WriteLine("Super silly distribution in action!"); var ssd = new SuperSillyContinuousDistribution(ssg); Console.WriteLine(ssd.NextDouble()); Console.WriteLine(ssd.NextDouble()); Console.WriteLine(ssd.NextDouble()); Console.WriteLine(); // 3) Use SuperSillyGenerator with a normal distribution. Console.WriteLine("Super silly generator with a normal distribution"); var normal = new NormalDistribution(ssg, 0, 1); Console.WriteLine(normal.NextDouble()); Console.WriteLine(normal.NextDouble()); Console.WriteLine(normal.NextDouble()); Console.WriteLine(); // 4) Change the core logic of normal distribution with a... Silly one. Console.WriteLine("Super silly redefinition of a normal distribution"); NormalDistribution.Sample = (generator, mu, sigma) => { // Silly method!!! return(generator.NextDouble() + mu + sigma + mu * sigma); }; Console.WriteLine(normal.NextDouble()); Console.WriteLine(normal.NextDouble()); Console.WriteLine(normal.NextDouble()); Console.WriteLine(); // 5) Use the new logic, even through TRandom. Console.WriteLine("Super silly redefinition of a normal distribution - via TRandom"); var trandom = TRandom.New(); Console.WriteLine(trandom.Normal(5, 0.5)); Console.WriteLine(trandom.Normal(5, 0.5)); Console.WriteLine(trandom.Normal(5, 0.5)); Console.WriteLine(); // 6) Use the extension method you defined for SuperSillyContinuousDistribution. Console.WriteLine("Super silly distribution via TRandom"); Console.WriteLine(trandom.SuperSilly()); Console.WriteLine(trandom.SuperSilly()); Console.WriteLine(trandom.SuperSilly()); }
// Simply call the static Sample you defined above. In the Main function, you can see that // this method can be used as other methods defined in TRandom. public static double SuperSilly(this TRandom r) => SuperSillyContinuousDistribution.Sample(r.Generator);