/// <summary> /// </summary> /// <param name="seed"></param> internal SimEnvironment(int seed) { // We add a dummy timeout event and a dummy process, so that heaps are never empty. They // have the maximum priority available, since they never have to be called. const double maxPr = double.PositiveInfinity; const ulong maxVer = ulong.MaxValue; var dummyP = new SimProcess(this, DummyProcess()) { At = maxPr, Version = maxVer }; var dummyEv = new Dummy(this) { At = maxPr, Version = maxVer }; _processes = new OptimizedSkewHeap(dummyP); _events = new OptimizedSkewHeap(dummyEv); Random = TRandom.New(new MT19937Generator(seed)); EndEvent = new Dummy(this); }
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()); }