# zeroes in random number generators VSLf

## zeroes in random number generators VSLf

I just went throughsome random-number generator examples (e.g.vsrnguniform.f and vsrngnegbinomial.f) included in the VSL for Fortran and noticed that all series of random numbers start with a leading zero.Why? This zero isalso included in the calculation of mean and variance. If you reduce the sample size (paramters nn and n in the example code) you can see that the mean and variancebecome highly affected by that zero. Is that a bug or is there a deeper reason? Thanks for helping!

3 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

Quoting - jeichner

I just went throughsome random-number generator examples (e.g.vsrnguniform.f and vsrngnegbinomial.f) included in the VSL for Fortran and noticed that all series of random numbers start with a leading zero.Why? This zero isalso included in the calculation of mean and variance. If you reduce the sample size (paramters nn and n in the example code) you can see that the mean and variancebecome highly affected by that zero. Is that a bug or is there a deeper reason? Thanks for helping!

Fortran examples you listed use MCG31 BRNG which is initialized with a seed equal to 1. Some of VSL BRNGs like 31-bit multiplicate congruantial generator MCG31 or 59-bit multiplicative congruential generator MCG59 return scaled seed as the first generated random number. For this reason 1st number produced by double precision version of MCG31 BRNG in the example vdrnguniform.f is somewhat 1.0/(double)(2^31-1) that is, 4.656612875245797E-010. In order to produce first random number which is far from zero, please set seed to a different value, use another VSL BRNG, for example MT19937 or just discard first random number. Additional details regarding initialization of VSL BRNGs are available in Vslnotes.pdf.

Quoting - Andrey Nikolaev (Intel)

Fortran examples you listed use MCG31 BRNG which is initialized with a seed equal to 1. Some of VSL BRNGs like 31-bit multiplicate congruantial generator MCG31 or 59-bit multiplicative congruential generator MCG59 return scaled seed as the first generated random number. For this reason 1st number produced by double precision version of MCG31 BRNG in the example vdrnguniform.f is somewhat 1.0/(double)(2^31-1) that is, 4.656612875245797E-010. In order to produce first random number which is far from zero, please set seed to a different value, use another VSL BRNG, for example MT19937 or just discard first random number. Additional details regarding initialization of VSL BRNGs are available in Vslnotes.pdf.

Thanks a lot for the fast answer! I tried seeds different from1, and up to 7 digit seeds I still get zeroes for the first random value. Then slowly the firstzero starts to change. Shouldn't there be an internal routine that takes care of that?Of course dropping the first (or more) number(s) is the best soloution, but in the following calculations in the example code the first value isn't dropped and especially forSMALL sample sizes a wrong estimator for the variance is used (assuming a vanishing covariance and dividing by n instead of n-1).

However, it's cool to have such powerfull tools for all different distributions provided in the VSL! Thanks!

Jan