//%jsroot on
double aRandom(TRandom3 *rn)
{ double rx=rn->Rndm();
if(rx<0.5) return rx*0.6;//0-0.3
else return (rx-0.5)*0.6+0.7;//0.7-1
}
TRandom3 *rn=new TRandom3();
rn->SetSeed(0);
TCanvas c;
Rndm表示0-1之间随机均匀抽样。
cout<<rn->Rndm()<<'\t'<<rn->Rndm()<<'\t'<<rn->Rndm();
TH1F *hrndm=new TH1F("hrndm","hrndm",100,0,100);
for(int i=0;i<10000;i++)
hrndm->Fill(rn->Rndm()*100);
hrndm->Draw();
hrndm->SetMinimum(0);
c.Draw();
c.Clear();
TH1F *hgaus=new TH1F("hgaus","hgaus",100,0,100);
for(int i=0;i<100000;i++)
hgaus->Fill(rn->Gaus(40,10));
hgaus->Draw();
c.Draw();
c.Clear();
TH1F *hbinomial=new TH1F("hbinomial","hbinomial",20,0,20);
for(int i=0;i<1000;i++)
hbinomial->Fill(rn->Binomial(100,0.03));//N is binomially distributed between 0 and ntot inclusive with mean prob*ntot and prob is between 0 and 1.
hbinomial->Draw();
c.Draw();
c.Clear();
TH1F *hexp=new TH1F("hexp","hexp",100,0,100);
for(int i=0;i<10000;i++)
hexp->Fill(rn->Exp(10));
gPad->SetLogy();
hexp->Draw();
c.Draw();
c.Clear();
TH1F *h0=new TH1F("h0","subrange uniform distribution",100,0,100);
for(int i=0;i<10000;i++) {
h0->Fill(aRandom(rn)*100);
}
gPad->SetLogy(0);
h0->Draw();
c.Draw();
c.Clear();
TH1F *h2=new TH1F("h2","sum1-2",200,0,100);
TH1F *h5=new TH1F("h5","sum1-5",200,0,100);
TH1F *h10=new TH1F("h10","sum1-10",200,0,100);
TH1F *h20=new TH1F("h20","sum1-20",200,0,100);
TH1F *h50=new TH1F("h100","sum1-100",200,0,100);
h2->SetLineColor(kBlack);
h5->SetLineColor(kGreen);
h10->SetLineColor(kBlue);
h20->SetLineColor(kRed);
for(int i=0;i<100000;i++) {
double rx=0;
for(int j=0;j<100;j++) {
rx += aRandom(rn);
if(j==1) h2->Fill(rx*50);
if(j==4) h5->Fill(rx*20);
if(j==9) h10->Fill(rx*10);
if(j==19) h20->Fill(rx*5);
if(j==99) h50->Fill(rx);
}
}
gPad->SetLogy(0);
h2->Draw();
c.Draw();
h5->Draw();
c.Draw();
h10->Draw();
c.Draw();
h20->Draw();
c.Draw();
h100->Draw();
c.Draw();
!jupyter nbconvert centerlimit.ipynb --to html