double exp_rand(); void rand_exp() { TCanvas *c1 = new TCanvas("c1","c1"); c1->SetGrid(); c1->SetFillColor(10); TH1F *h1 = new TH1F("h1","",300,0,30); double value; for (int i=0; i<1000; i++) { value = exp_rand(); h1->Fill(value); } h1->Draw(); } double exp_rand() { double t_const = 3.7*1.2/0.494; double x_max=30.; double y_max=1.; double x, y; double value; while (1) { x = gRandom->Uniform()*x_max; value = exp(-x/t_const); y = gRandom->Uniform()*y_max; if (y <= value) break; } return x; }