예제 #1
0
        private void gaussMagicButton_Click(object sender, EventArgs e)
        {
            var M         = (double)gaussMNumericUpDown.Value;
            var Q         = (double)gaussQNumericUpDown.Value;
            var generator = new GaussGenerator(randomGenerator, M, Q);
            var sequence  = new Sequence(generator, SequenceLength);

            ShowValues(sequence, null, null);
        }
예제 #2
0
        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.");
            });
        }