3

I need to use normally distributed random numbers in my program. Let's say I need to generate x (size is R^(m x n) ) whose elements are from the Gaussian distribution of zero mean and one variance. How do I do this in C with good accuracy?

user3727929
  • 135
  • 4

1 Answers1

1

There are a lot of algorithms to produce a normal distribution if you have a uniform random generator. Have a look at this section of the wikipedia article. One possible approach is by using the central limit theorem. The approach here would be to generate many integer values with uniform distribution and then compute their arithmetic mean.

Ivaylo Strandjev
  • 64,309
  • 15
  • 111
  • 164
  • The most practical approach? It takes a dozen uniform samples to get a single variable that's at least roughly normal distributed, and far more to get better approximations. It's not like the Box-Muller method is particularly complicated. It only needs square root, logarithm, and trigonometry - i.e. `libm`. Probably not even more lines of code. –  Oct 24 '14 at 18:41
  • @delnan actually I did not read all the suggested ideas. I have simply done something similar with central limit theorem. I will re-phrase the answer. – Ivaylo Strandjev Oct 24 '14 at 18:42