float getExpRndmNumber(int max){ //Implementation of the function. float x = 0; float y = 0; do { x = max * gRandom->Uniform(0,1); y = gRandom->Uniform(0,1);} while (y> TMath::Exp(-x)); return x; } int ex12_frwl(){ TH1F* h1 = new TH1F("h1", "Exponentialverteilung", 100, 0, 10); const int iterations = 10000; for (int ii = 0; ii < 10000; ii++){ h1->Fill(getExpRndmNumber(10)); } h1->Draw(); TF1* myExp = new TF1("myExp", "[0]*TMath::Exp(-x)", 0,10); // Normalisation has to be #iterations divided by #bins multiplied by range. myExp->SetParameter(0, iterations/10.); myExp->Draw("same"); }