Getting StartedΒΆ
To use NVPL RAND library, users include the header file, nvpl_rand.h
to get function declarations, and link against NVPL RAND library. The same header file is used for either single-threaded or multi-threaded NVPL RAND library.
Random numbers are produced by generators. To create a new generator handle of the desired type (see Generator Types):
for single-threaded generator, use
nvplRandCreateGenerator()
.for multi-threaded generator, use
either
nvplRandMTCreateGenerator()
by specifying the number of threads to use by the generator,or
nvplRandMTCreateGeneratorDefault()
. The default number of threads used in the API is the number of concurrent threads supported by the system.
Note
While an application using NVPL RAND multi-threaded APIs, i.e., APIs with nvplRandMT
prefix, is required to dynamically link to the multi-threaded library libnvpl_rand_mt.so
, an application using only single-threaded generators can link to either libnvpl_rand.so
or libnvpl_rand_mt.so
.
After creating the generator, there are multiple generator options users can choose to set, for example:
nvplRandSetPseudoRandomGeneratorSeed()
to set the seed for pseudorandom generators,nvplRandSetGeneratorOffset()
to set the offset,nvplRandSetQuasiRandomGeneratorDimensions()
to set the number of dimensions for quasirandom generators,for multi-threaded generators,
nvplRandMTSetGeneratorOrdering()
to set the ordering of the results.
Note
The default values of seed, offset, or ordering are usually sufficient for most cases, therefore using these APIs is optional.
Generating random numbers is done with
nvplRandGenerate()
to generate 32-bit integers, or another generation function to generate floating point or integer numbers with specific distributions, for example,nvplRandGenerateUniform()
for uniformly distributed FP32 numbers, or genericnvplRandGenerateDistribution()
for random numbers with Gamma distribution (See Generation Functions).