ran1 in VBA


Aditya
01-09-2003, 02:48 AM
I rewrote the c++ code of ran1 and gasdev in VB and generated 5000 random numbers. The resulting series has a mean of 0.056 and SD of 1.0067. I need the mean and SD to be very close to 0 and 1 respectively.

Does the C++ code give more accurate result?

Kevin Dolan
01-09-2003, 04:22 PM
Hard to say. The mean you show is pretty far from zero for the number of points you used. The standard deviation of the expectation value of the mean, for a sample size of 5000, should be 1/sqrt(5000), or about 0.014. Your standard deviation looks fine, though.

Did you try running it multiple times? How consistent are the results? On average, for this many points, you should expect the mean to be somewhere around +- 0.014, and the standard deviation should be something like 1 +- 0.01. Those are approximately the standard deviations of the expectation values of those quantities for a sample size of 5000. You can't really estimate the quality from one trial, so I would recommend running it multiple times, and seeing how it matches up with what would be expected.

Dr. Stupid

Aditya
01-23-2003, 12:20 AM
Thank you for the prompt reply.

I have run it multiple times and still the mean and SD are on average in the same range. I think the problem is in the ran1 part. These are the mean and SD for 10 sets, each set having 5000 random numbers.

MEAN: 0.50196, 0.49449, 0.49607, 0.50257, 0.50196, 0.49665, 0.49472, 0.50523, 0.50120, 0.50635

SD: 0.28872, 0.28795, 0.29091, 0.28636, 0.28950, 0.28741, 0.28347, 0.28844, 0.28497, 0.28763

Would the result be in the above range if I executed the ran1 code in c++ ?

I need to generate sets non-correlated normally distributed random numbers (mean and SD very close to 0 and 1 respectively having non-significant kurtosis and skew).

Should I try some other algorithm for achieving the above?

Thanks,

Kevin Dolan
01-25-2003, 05:42 AM
Aditya,

Your numbers look just fine to me. The standard deviation of your sample mean seems to be about 0.013, which is about what should be expected for a sample size of 5000.

Remember that a good random number generator should not be expected to produce a set of numbers with exactly the same moments as the theoretical distribution. The sample mean, sample variance, etc... should all converge to those of the theoretical distribution in the limit of very large sample sizes. For a sample size of 5000 points, the values you have gotten are about what should be expected.

Kevin Dolan