// Треугольное распределение private void TriangleDistribution() { LehmerRandom rand = new LehmerRandom(ulong.Parse(textBox_a.Text), ulong.Parse(textBox_m.Text), ulong.Parse(textBox_R0.Text)); int N = int.Parse(textBox3.Text); double a = double.Parse(textBox1.Text); double b = double.Parse(textBox2.Text); randArray = new double[N]; for (int i = 0; i < N; i++) { double R1 = rand.Next(); double R2 = rand.Next(); randArray[i] = a + (b - a) * Math.Max(R1, R2); } CalculateStatValues(); DrawHistogram(); distNameLabel.Text = "Треугольное распределение\r\na = " + a.ToString() + ", b = " + b.ToString() + ", N = " + N.ToString(); }
// Экспоненциальное распределение private void ExponentialDistribution() { LehmerRandom rand = new LehmerRandom(ulong.Parse(textBox_a.Text), ulong.Parse(textBox_m.Text), ulong.Parse(textBox_R0.Text)); int N = int.Parse(textBox5.Text); // Количество генерируемых чисел double λ = double.Parse(textBox1.Text); // Параметр экспоненциального распределения randArray = new double[N]; for (int i = 0; i < N; i++) { randArray[i] = -Math.Log(rand.Next()) / λ; } CalculateStatValues(); DrawHistogram(); }
// Распределение Симпсона private void SimpsonDistribution() { LehmerRandom rand = new LehmerRandom(ulong.Parse(textBox_a.Text), ulong.Parse(textBox_m.Text), ulong.Parse(textBox_R0.Text)); int N = int.Parse(textBox3.Text); double a = double.Parse(textBox1.Text); double b = double.Parse(textBox2.Text); randArray = new double[N]; for (int i = 0; i < N; i++) { randArray[i] = a / 2 + (b / 2 - a / 2) * rand.Next() + a / 2 + (b / 2 - a / 2) * rand.Next(); } CalculateStatValues(); DrawHistogram(); distNameLabel.Text = "Распределение Симпсона\r\na = " + a.ToString() + ", b = " + b.ToString() + ", N = " + N.ToString(); }
// Гамма-распределение private void GammaDistribution() { LehmerRandom rand = new LehmerRandom(ulong.Parse(textBox_a.Text), ulong.Parse(textBox_m.Text), ulong.Parse(textBox_R0.Text)); int N = int.Parse(textBox5.Text); // Количество генерируемых чисел int η = int.Parse(textBox1.Text); double λ = double.Parse(textBox2.Text); randArray = new double[N]; for (int i = 0; i < N; i++) { double tmp = 1; for (int j = 0; j < η; j++) { tmp *= rand.Next(); } randArray[i] = -Math.Log(tmp) / λ; } CalculateStatValues(); DrawHistogram(); }
private void button1_Click(object sender, EventArgs e) { LehmerRandom rand = new LehmerRandom(ulong.Parse(textBox_a.Text), ulong.Parse(textBox_m.Text), ulong.Parse(textBox_R0.Text)); int N = Int32.Parse(textBox5.Text); randArray = new double[N]; for (int i = 0; i < N; i++) { randArray[i] = rand.Next(); } CalculateStatValues(); DrawHistogram(); if (randArray == null) { return; } for (int i = 0; i < randArray.Length; i++) { listBox1.Items.Add(randArray[i].ToString("0.#####")); } var n = randArray.Length; var k = 0; for (var i = 0; i < n / 2; i++) { if (Math.Pow(randArray[i], 2) + Math.Pow(randArray[i + 1], 2) < 1) { k++; } } var p = (double)2 * k / n; textBox6.Text = p.ToString(); }
// Гамма-распределение private void GammaDistribution() { LehmerRandom rand = new LehmerRandom(ulong.Parse(textBox_a.Text), ulong.Parse(textBox_m.Text), ulong.Parse(textBox_R0.Text)); int N = int.Parse(textBox3.Text); // Количество генерируемых чисел int η = int.Parse(textBox1.Text); double λ = double.Parse(textBox2.Text); randArray = new double[N]; for (int i = 0; i < N; i++) { double tmp = 1; for (int j = 0; j < η; j++) { tmp *= rand.Next(); } randArray[i] = -Math.Log(tmp) / λ; } CalculateStatValues(); DrawHistogram(); distNameLabel.Text = "Гамма-распределение\r\nη = " + η.ToString() + ", λ = " + λ.ToString() + ", N = " + N.ToString(); }
// Гауссовское распределение private void GaussDistribution() { LehmerRandom rand = new LehmerRandom(ulong.Parse(textBox_a.Text), ulong.Parse(textBox_m.Text), ulong.Parse(textBox_R0.Text)); int N = int.Parse(textBox5.Text); // Количество генерируемых чисел double m = double.Parse(textBox1.Text); // Мат. ожидание double sko = double.Parse(textBox2.Text); // СКО int n = int.Parse(textBox3.Text); // Число суммируемых равномерно распределённых чисел randArray = new double[N]; for (int i = 0; i < N; i++) { double tmp = 0; for (int j = 0; j < n; j++) { tmp += rand.Next(); } randArray[i] = m + sko * Math.Sqrt(12.0 / n) * (tmp - (double)n / 2); } CalculateStatValues(); DrawHistogram(); }