private int findPeriod() { RandomSequence = new List <double>(); for (int i = 0; i < SEQUENCE_MAX_LENGTH; i++) { RandomSequence.Add(LemerRandom.Next()); } double Xv = LemerRandom.CurrentX(); // find period int i1 = -1, i2 = -1; bool flag = false; for (int i = 0; i < RandomSequence.Count; i++) { if (RandomSequence[i] == Xv) { if (!flag) { flag = true; i1 = i; } else { i2 = i; break; } } } int period = i2 - i1; // Find aperiod length int i3 = 0; while (RandomSequence[i3] != RandomSequence[i3 + period]) { i3++; } int aperiod = i3 + period; RandomSequence.RemoveRange(aperiod, RandomSequence.Count - aperiod); if (i2 == -1 || i1 == -1) { textBox_period.Text = "Period unfind"; } else { textBox_period.Text = period.ToString(); // Период textBox_no_period.Text = aperiod.ToString(); // Длина участка апериодичности } return(period); }
// Треугольное распределение private void TriangleRaspred() { LemerRandomSequence rand = new LemerRandomSequence(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); RandomSequence = new double[N]; for (int i = 0; i < N; i++) { double R1 = rand.Next(); double R2 = rand.Next(); RandomSequence[i] = a + (b - a) * Math.Max(R1, R2); } CalculateStatValues(); DrawHistogram(); distNameLabel.Text = "Треугольное распределение\r\na = " + a.ToString() + ", b = " + b.ToString() + ", N = " + N.ToString(); }
// Экспоненциальное распределение private void ExponentialRaspred() { LemerRandomSequence rand = new LemerRandomSequence(ulong.Parse(textBox_a.Text), ulong.Parse(textBox_m.Text), ulong.Parse(textBox_R0.Text)); int N = int.Parse(textBox2.Text); // Количество генерируемых чисел double λ = double.Parse(textBox1.Text); // Параметр экспоненциального распределения RandomSequence = new double[N]; for (int i = 0; i < N; i++) { RandomSequence[i] = -Math.Log(rand.Next()) / λ; } CalculateStatValues(); DrawHistogram(); distNameLabel.Text = "Экспоненциальное распределение\r\nλ = " + λ.ToString() + ", N = " + N.ToString(); }
private void SimpsonRaspred() { LemerRandomSequence rand = new LemerRandomSequence(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); RandomSequence = new double[N]; for (int i = 0; i < N; i++) { RandomSequence[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 UniformDistrib() { LemerRandomSequence rand = new LemerRandomSequence(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); RandomSequence = new double[N]; for (int i = 0; i < N; i++) { RandomSequence[i] = a + (b - a) * rand.Next(); } CalculateStatValues(); DrawHistogram(); distNameLabel.Text = "Равномерное распределение\r\na = " + a.ToString() + ", b = " + b.ToString() + ", N = " + N.ToString(); }
// Гамма-распределение private void GammaRaspred() { LemerRandomSequence rand = new LemerRandomSequence(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); RandomSequence = new double[N]; for (int i = 0; i < N; i++) { double tmp = 1; for (int j = 0; j < η; j++) { tmp *= rand.Next(); } RandomSequence[i] = -Math.Log(tmp) / λ; } CalculateStatValues(); DrawHistogram(); distNameLabel.Text = "Гамма-распределение\r\nη = " + η.ToString() + ", λ = " + λ.ToString() + ", N = " + N.ToString(); }
// Гауссовское распределение private void GaussRaspred() { LemerRandomSequence rand = new LemerRandomSequence(ulong.Parse(textBox_a.Text), ulong.Parse(textBox_m.Text), ulong.Parse(textBox_R0.Text)); int N = int.Parse(textBox4.Text); // Количество генерируемых чисел double m = double.Parse(textBox1.Text); // Мат. ожидание double sko = double.Parse(textBox2.Text); // СКО int n = int.Parse(textBox3.Text); // Число суммируемых равномерно распределённых чисел RandomSequence = new double[N]; for (int i = 0; i < N; i++) { double tmp = 0; for (int j = 0; j < n; j++) { tmp += rand.Next(); } RandomSequence[i] = m + sko * Math.Sqrt(12.0 / n) * (tmp - (double)n / 2); } CalculateStatValues(); DrawHistogram(); distNameLabel.Text = "Гауссовское распределение\r\nm = " + m.ToString() + ", σ = " + sko.ToString() + ", N = " + N.ToString(); }