根据连续分布产生随机数一般方法

来源:互联网 发布:linux初学者入门书籍 编辑:程序博客网 时间:2024/06/08 03:18
/////////////////////////////////////////////////////this program generates random number according to //the continues distribution////auther :HuiLi 3/16/2016 00:59/////////////////////////////////////////////////////void f1(){double F,A;auto h1=new TH1D("continuent","A;x_{t};count",1000,0,1);auto h2=new TH1D("h2","A;x_{t};count",1000,0,1);TRandom3 r;double t;for (int i=0;i<100000 i="" f="pow(r.Uniform(),2)*0.5;" t="pow(2*F,1.0/2);" h1-="">Fill(t);}////归一化normalization//for(i=1;i<=1000;i++){ A=1./1000*(h1->GetBinContent(i));h2->SetBinContent(i,A);} auto c1 =new TCanvas(); c1->Divide(1,2); c1->cd(1); h1->Draw(); h1->Scale();//h1->Draw(); c1->cd(2); h2->Draw();}
0 0
原创粉丝点击