-1

I want to generate discrete random numbers (for 1000 ensemble) with Gaussian distribution with mean zero and variance 2.25. I saw in the book NUMERICAL RECIPES in Fortran 90, chapter 7, section 7.2, the function gasdev used for this, but I don't know how to use this function.

How can I use the number of ensembles and mean and variance?

Thank you

HeatfanJohn
  • 7,143
  • 2
  • 35
  • 41

2 Answers2

1

IMO, how to use a function from NR is best written in NR itself.

If you need to generate normally distributed real numbers, google for "Box-Muller transform", or go directly to the Wiki page and/or dozens questions and answers here on SO.

If your requirement is to generate integers (did you mean that by asking about discrete random numbers?), I'd say the easiest way is to compute the cdf.

Community
  • 1
  • 1
ev-br
  • 24,968
  • 9
  • 65
  • 78
  • I want to generate discrete random numbers (for 1000 ensemble) with Gaussian distribution with mean zero and variance 2.25. How can I do that? – user1272138 Jul 08 '12 at 21:45
0

gasdev returns normally distributed random variable with mean of 0.0 and variance of 1.0, often written as N(0, 1). You should scale the result with the variance in order to match the desired distribution. Note that if x is N(0, 1) (as returned by gasdev), then y = a + b*x is N(a, b^2), i.e. normally distributed random variable with mean of a and variance of b^2.

(btw, if this is a homework, it should be properly tagged as such)

Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186