How to make a histogram with random numbers interactively?

Hi,

Interactively, I can do

root [22] TH1F* h1 = new TH1F(“h1”,“Random Gaussian”,100,-2,2);
root [23] h1->FillRandom(“gaus”,10000);

and that works fine.

However, I want to fill it with random nos. uniformly distributed between 0 and 1. I tried,

root [1] TH1F* h1 = new TH1F(“h1”,“flat”,100,-1,1);
root [27] h1->FillRandom(“rndm”,10000);
Error in : Unknown function: rndm
root [28] h1->FillRandom(“Rndm”,10000);
Error in : Unknown function: Rndm

I know how to do this from inside a macro.

Basically, I want to fill a 2-D histogram with a flat distribution, but I am kind fo stuck at the first stage.

vivek

p.s. I also tried using uniform instead of rndm, but no success.

1 Like

[quote=“vivekj”]Hi,

Interactively, I can do

root [22] TH1F* h1 = new TH1F(“h1”,“Random Gaussian”,100,-2,2);
root [23] h1->FillRandom(“gaus”,10000);

and that works fine.

However, I want to fill it with random nos. uniformly distributed between 0 and 1. I tried,

root [1] TH1F* h1 = new TH1F(“h1”,“flat”,100,-1,1);
root [27] h1->FillRandom(“rndm”,10000);
Error in : Unknown function: rndm
root [28] h1->FillRandom(“Rndm”,10000);
Error in : Unknown function: Rndm

I know how to do this from inside a macro.

Basically, I want to fill a 2-D histogram with a flat distribution, but I am kind fo stuck at the first stage.

vivek

p.s. I also tried using uniform instead of rndm, but no success.[/quote]

To call the TH1::FillRandom() method could exist a function with the same name, for a uniform distribution I think you can use the “pol0” function.