Erlang Random Distribution

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Markup;

namespace erlangdistribution
{    
    public partial class erlangFrom : Form
    {   //泊松分布,指数分布,爱尔朗分布都是应用与Queuing theory排队概率分析
        // generate(0,1)interval random number
        Random rd = new Random(Guid.NewGuid().GetHashCode());
        //double uniform(double double int*)        
        public erlangFrom()
        {
            InitializeComponent();
        }
        double erlang(int m,double b)
        { //erlang distribution
          double r = 1.0;
          for ( int i = 0; i < m;i++)
            r *= rd.NextDouble();
            r =-b/Math.Log(r);
            return r;
        }
        static long fact(int n){ //N! the factorial of N
            long r = 1;
            if (n == 0) return 1;
            for (int i = 1; i <= n; i++) r *= i;
            return r;
        }
        private void btCreateData_Click(object sender, EventArgs e)
        {
            double r;
            double[] value = new double[50];
            int m = 3;  double b=1.0;

            for (int i = 0; i < value.Length; i++){ 
                value[i] = 0.0;
            }
            tbPointData.Clear();
            tbDensityData.Clear();
            foreach (var series in chart_PointDistribute.Series){
                series.Points.Clear();
            }
            foreach (var series in chart_MakeCurve.Series){
                series.Points.Clear();
            }
            //Erlang scatter diagram
            for (int i = 0; i < 10; i++){
                for (int j = 0; j < 5; j++){
                    r=erlang(m, b);                    
                    value[i * 5 + j] = r;
                    this.chart_PointDistribute.Series[0].Points.AddXY(i * 5 + j, r);
                    tbPointData.AppendText((i * 5 + j).ToString() + ": 	" + r.ToString("f6") + "	
  ");
                }
            }
            //f(x)=((β^-m*x^m-1)/(m-1)!)*e^(-x/β) 密度函数
            double[] density = new double[50];
            for (int i = 0; i < 50; i++){
                density[i] = Math.Pow(b,-m)*Math.Pow(i,m-1)* Math.Pow(Math.E, -i / b) / fact(m);
            }
            for (int i = 0; i < 50; i++){
                this.chart_MakeCurve.Series[0].Points.AddXY(i, density[i]);
                tbDensityData.AppendText("X is:" + i.ToString("f0") + "	" + "Density is:" + density[i].ToString("f4") + "	
");
            }
        }
    }
}

埃尔朗分布散点图密度函数资源-CSDN文库