private async void GenerateButton_Click(object sender, EventArgs e) { int count = (int)CountInput.Value; int seed = (int)SeedInput.Value; int multiplier = (int)MultiplierInput.Value; int range = (int)RangeInput.Value; bool showAllNumbers = !DisplayedNumbersLimiter.Checked; MLCG generator = new MLCG(seed, multiplier, range); // Set max progressbar GeneratingProgress.Maximum = count; ClearComponents(); // Generating numbers await Task.Factory.StartNew(() => { ProgressStage("Generating numbers..."); for (int i = 0; i < count; i++) { if (showAllNumbers || i < 100) { string row = $"{i + 1}. {generator.NextNumber()}"; ExecuteInUIThread(() => NumbersList.Items.Add(row)); } else { generator.NextNumber(); } ExecuteInUIThread(() => GeneratingProgress.Value++); } }); ProgressStage("Calculating statistics..."); Calculations calculations = new Calculations(generator); AddToOutputBox($"M = {calculations.ExpectedValue:F5}"); AddToOutputBox($"D = {calculations.Variance:F5}"); AddToOutputBox($"σ = {calculations.StandardDeviation:F5}"); ProgressStage("Building plot..."); calculations.BuildHistogram(Plot.plt); Plot.Render(); ProgressStage("Calculating distribution evenness..."); calculations.EstimateDistributionEvenness(); AddToOutputBox($"2K/N = {calculations.EstimateDistributionEvenness():F5} -> {Math.PI / 4:F5}"); ProgressStage("Calculating period..."); int period = calculations.Period; int aperiodicitySegment = calculations.AperiodicitySegment; AddToOutputBox(period != 0 ? $"P = {period}" : "Not enough numbers to calculate period."); AddToOutputBox(aperiodicitySegment != 0 ? $"L = {aperiodicitySegment}" : "Not enough numbers to calculate aperiodicity segment."); ProgressStage("Complete."); }
public Calculations(MLCG generator) { _sequence = generator.Sequence; CalculateStatistics(); _plotMin = 0; _plotMax = 1; CalculatePeriodAndAperiodicitySegment(generator.Multiplier, generator.Modulus, generator.Increment); }
private async void GenerateButton_Click(object sender, EventArgs e) { string distribution = DistributionComboBox.SelectedItem.ToString(); int count = (int)CountInput.Value; int seed = (int)SeedInput.Value; int multiplier = (int)MultiplierInput.Value; int range = (int)RangeInput.Value; bool showAllNumbers = !DisplayedNumbersLimiter.Checked; IGenerator generator; MLCG generatorMLCG = new MLCG(seed, multiplier, range); ClearComponents(); GeneratingProgress.Maximum = count; switch (distribution) { case "Uniform": generator = new UniformGenerator(Input1.Value, Input2.Value, generatorMLCG); break; case "Gauss": generator = new GaussGenerator(Input1.Value, Input2.Value, Input3.Value, count, generatorMLCG); break; case "Exponential": generator = new ExponentialGenerator(Input1.Value, generatorMLCG); break; case "Gamma": generator = new GammaGenerator(Input1.Value, Input2.Value, count, generatorMLCG); break; case "Triangular": generator = new TriangularGenerator(Input1.Value, Input2.Value, TriangularMinCheckBox.Checked, count, generatorMLCG); break; case "Simpson": generator = new SimpsonGenerator(Input1.Value, Input2.Value, count, generatorMLCG); break; default: generator = generatorMLCG; break; } await Task.Factory.StartNew(() => { ProgressStage("Generating numbers..."); for (int i = 0; i < count; i++) { if (showAllNumbers || i < 100) { string row = $"{i + 1}. {generator.NextNumber()}"; ExecuteInUIThread(() => NumbersList.Items.Add(row)); } else { generator.NextNumber(); } ExecuteInUIThread(() => GeneratingProgress.Value++); } ProgressStage("Calculating statistics..."); Calculations calculations = new Calculations(generator); AddToOutputBox($"M = {calculations.ExpectedValue:F5}"); AddToOutputBox($"D = {calculations.Variance:F5}"); AddToOutputBox($"σ = {calculations.StandardDeviation:F5}"); ProgressStage("Building plot..."); calculations.BuildHistogram(Plot.plt); Plot.Render(); ProgressStage("Complete."); }); }