Random numbers from -10 - 10

Hi,

I am trying to just plot a bunch of random points from -10 - 10 using Rndm(). I am having trouble figuring out how to apply it and use it. Here is what I wrote:

void Random(){
TH1D *h = new TH1D(“h”. “h”, 10, 10, 10);
for(int i = 0; i<100; i++){
double val = new Rndm()*10;
h->AddPoint(val);
}
h->Draw();

TRandom3 r;
// ...
for(int i = 0; i<100; i++){
 double val = r.Rndm()*10;
//...

But note than Rndm() produces numbers from 0 to 1, not -1 to 1.

{
   TH1D *h = new TH1D("h", "h", 10, -10, 10);
   for(int i = 0; i<100; i++) h->Fill(gRandom->Rndm()*20-10);
   h->Draw();
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.