Generate random numbers

(1) How do I generate random numbers in ROOT? I wanted to use random numbers between 2.5 and 5.0 but with more favor on the 5.0 than 2.5. Where numbers closer to 5.0 occur twice as those closer to 2.5.
(2) What do you mean by “normalized Gaussian prior |x| < 2”? Does it mean this:
gRandom->Gaus(0.0,2.0)…

thanks in advance for your help.

regards,
jaybee

2 Likes

Hi @jbmagallanes,
about 1: you can generate random numbers using TRandom3, e.g.

TRandom3 r;
const auto random_number = r.Rndm ()

That gives you pseudo-random numbers distributed uniformly between 0 and 1. You should be able to manipulate the uniform distributions to get the distribution you want.

About 2: can you provide a bit more context for the quote?

Cheers,
Enrico

1 Like

thanks Enrico… for number 2, it’s like get a number in |x| < 2 with a normalized gaussian distribution. i don’t know if i got it right… for number 1, i am still thinking deeply…

1 Like

Hi,

for (1) you need to assume a distribution from which generate. For example you can use a linear function that is equal to 1 for x = 2.5 and 2 for x = 5
Example:

TF1 f("f","(1./2.5)*x",2.5,5.);
double x = f.GetRandom();

for 1) you need to generate using gRandom->Gaus(0,1) and discard the numbers greater or equal than 2.

1 Like

Gracias :slight_smile:

1 Like

Thanks and how to make generation of 3 arrays

can you elaborate more?

gracias, @moneta :slight_smile: