# White Noise Generation in ROOT

Hello, everyone.
Does anyone know how we can generate white noise in ROOT?
Thank you

Dear chlee91,

Could you be more specific on what you need?
ROOT has interfaces to several random generators via the abstract interface TRandom.

G Ganis

I want to plot the graph which is similar to the one in this picture. I have tried to used TRandom3() function, and fill canvas with Uniform(). But the numbers generated are all positive numbers. However, i need the numbers scattered about the line of y=0.

``````{
Double_t px,py;
TGraph *g = new TGraph();
for (int i=0; i<1000; i++) {
gRandom->Rannor(px,py);
g->SetPoint(i,i,py);
}
g->Draw("AL")
}
``````

gives:

Thank you, Couet.But how can i manipulate the range of x-axis, for example, 10000 entries within [100,200] for the x-axis?

The x axis range is define by the x values of the points in the graph. It is up to you to define the X points. In the example I gave you I just simply put the index of the loop as x values. So instead of:

``````g->SetPoint(i,i,py);
``````

do:

``````g->SetPoint(i,x,py);
``````

where x will be equally distributed between 100 et 200

Thanks again, Couet. But what i mean is, if i need 1000 entries generated in my plot within the range of [100, 200],how can it be done? In other words, the current code is where there are 1000 entries, so it will start from x=0 until x=1000… But what i really want is, i want to generate all the entries and squeeze them in a certain range but not start from zero. Thank you…

I understand what you meant. And that’s what I explained you. Here is the complete code:

``````{
double nb = 1000;
double x1 = 100;
double x2 = 200;
double dx = (x2-x1)/nb;
double x  = x1;
double px,py;

TGraph *g = new TGraph();

for (int i=0; i<nb; i++) {
gRandom->Rannor(px,py);
g->SetPoint(i,x,py);
x = x +dx;
}
g->Draw("AL")
}
``````

Thank you, Couet. Thanks for guiding me

Is it possible to change the value of standard deviation of Rannor ()?

I used Rannor as an example. You need to look at the TRandom documentation to tune the macro as you need and may be use something else than Rannor. That’s up to you.

Understood. Thank you!!!

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