# Random Sample

Generates random numbers following a standard normal distribution.

Controller: **CodeCogs**

## Dependents

## Interface

C++

## Class RandomSample

The general formula for the probability density function of the normal distribution is where is the <em>location parameter</em> and is the <em>scale parameter</em>. The case where and is called the standard normal distribution. Therefore the density of this particular distribution, which we also use with this random number generator is Using this class, the diagram below is generated from two distinct sequences of 1000 random numbers. Each pair of numbers are plotted against each other, to illustrate the standard normal behaviour of this non-uniform random number generator.## Speed:

The average running time for generating 100,000,000 random numbers using this class on a 750MHz microprocessor is 37 seconds.## References:

- NIST/SEMATECH e-Handbook of Statistical Methods, http://www.itl.nist.gov/div898/handbook/
- The Newran03 random number generator library of Robert Davies, http://www.robertnz.net/nr03doc.htm

### Example 1

- The following example displays 40 random floating point numbers from a standard normal distribution.
It uses two different generators to achieve this. The first generator uses a particular value
to initialize the seed, while the second one is using the system timer. Notice that it was necessary
to divide the timer with the MERSENNEDIV value in order to keep the seed in the (0, 1) interval.
Since the seed of the first generator is never changed, the first 20 numbers will always
remain the same. However since the second generator is initialized via the system timer,
the next 20 numbers will obviously vary with each execution of the program.
#include <iostream> #include <time.h> #include <codecogs/statistics/distributions/continuous/normal/randomsample.h> using namespace std; int main() { Stats::Dists::Continuous::Normal::RandomSample A(0.335); Stats::Dists::Continuous::Normal::RandomSample B(time(0) / MERSENNEDIV); for (int i = 0; i < 20; ++i) cout << A.genReal() << endl; cout << endl; for (int i = 0; i < 20; ++i) cout << B.genReal() << endl; return 0; }

Below you will find 20 numbers corresponding to the output of the first generator :0.0939832 1.91932 0.214906 0.538229 -1.74433 -0.494465 2.012 -0.457599 0.0605692 -0.350289 -0.72978 -1.48569 -0.369718 0.129291 -1.95127 0.151708 1.16571 -1.05828 -0.612659 1.04844

### Authors

*Lucian Bentea*

##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

## Members of RandomSample

#### RandomSample

Constructor that sets up the class variables and initializes the associated random number generator with the given seed.RandomSample( double `s``= 0.65234`

) *[constructor]*s Default value = 0.65234

## Sample

doublesample( | double | seed` = 0` | ) |

#include <time.h> ... sample(time(0) / MERSENNEDIV);If you require more advance behaviour, we strongly recommend that directly use the underlying class randomsample that is provided with this module.

### Parameters

seed sets the initial seed for the random generator. Only used in the first call to this function

##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

Last Modified: 12 Nov 10 @ 21:08 Page Rendered: 2022-03-14 13:50:15