Developer Reference


VS RNG Usage Model
Intel® oneMKL
RNG Usage Model

A typical algorithm for
random number generators is as follows:
  1. Create and initialize stream/streams. Functions
  2. Call one or more RNGs.
  3. Process the output.
  4. Delete the stream or streams with the function
You may reiterate steps 2-3. Random number streams may be generated for different threads.
The following example demonstrates generation of a random stream that is output of basic generator MT19937. The seed is equal to 777. The stream is used to generate 10,000 normally distributed random numbers in blocks of 1,000 random numbers with parameters
= 5 and
= 2. Delete the streams after completing the generation. The purpose of the example is to calculate the sample mean for normal distribution with the given parameters.
Example of VS RNG Usage
#include <stdio.h> #include "mkl_vsl.h"   int main() { double r[1000]; /* buffer for random numbers */ double s; /* average */ VSLStreamStatePtr stream; int i, j;   /* Initializing */ s = 0.0; vslNewStream( &stream, VSL_BRNG_MT19937, 777 );   /* Generating */ for ( i=0; i<10; i++ ) { vdRngGaussian( VSL_RNG_METHOD_GAUSSIAN_ICDF, stream, 1000, r, 5.0, 2.0 ); for ( j=0; j<1000; j++ ) { s += r[j]; } } s /= 10000.0;   /* Deleting the stream */ vslDeleteStream( &stream );   /* Printing results */ printf( "Sample mean of normal distribution = %f\n", s );   return 0; }
Additionally, examples that demonstrate usage of VS random number generators are available in:

Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804