This code generates a Normal distributed variable.

This cofde generates 12 (it's an importnat number) uniformly distributed variables (Xs)between -100 and 100 and adds them into a 1000 sample vector called gausian.

Of course, you can play with the parameters to satisfy your demands, but the important things are:

1) if you give Xs asymetric range , and you want a normal (i.e mean=0) distribution, don't forget to substract

range_size/2 from every sample.

2) The number 12 gives the std 1 because a uniform std is 0.25 =~sqrt(1/12) and by adding 12 Xs you obtain std=1

so if you change this number be sure to modify your std as well.

3) I gave an example with 1000 points. Of course, the more points-the more accurte distribution, but longer run.

The code includes coverage so that if you run it with specview and open the coverage window and look at samples

( under normal.collect) you can see graghically the distribution (flipped to the side)

author: Avi Farjoun updated 10/28/2004 1071 bytes

*Originally posted in cdnusers.org by*

**Administrator**