ExRandom
3.0
|
Here is how to use one of the *_dist classes. These are not C++11 random number distributions. But they offer the flexibility to access the u-rands generated by the algorithms. For example, the two functions to generate normal deviates are unit_normal_dist::generate and unit_normal_dist::value. The skeleton code to create and use these is
A complete example is sample_normal.cpp
Running this program gives, for example,
Sampling from the normal distribution Seed set to 237750281 Deviates rounded to floating point with base = 16 columns are: initial u-rand, rounded float, final u-rand -0... = -0.690407 = -0.b0be828... +0.1... = 0.0713383 = +0.124339d... -0... = -0.686044 = -0.afa08bb... +0.6... = 0.41938 = +0.6b5c7f9... +0.2... = 0.132118 = +0.21d2840... -1.3... = -1.2284 = -1.3a7842... +0.4... = 0.286089 = +0.493d257... +0... = 0.91659 = +0.eaa5ab4... +1.dc... = 1.86227 = +1.dcbdbe... +0... = 0.0933357 = +0.17e4d90... Total number of base 16 digits used = 162 Deviates rounded to fixed point with base = 10 and precision = 6 columns are: initial u-rand, rounded fixed, final u-rand +2.9... = +2.906062(+) = +2.9060622... -0... = -0.824044(-) = -0.8240438... +1.0... = +1.010208(-) = +1.0102079... +0.0... = +0.015557(-) = +0.0155568... +0... = +0.737249(+) = +0.7372493... +2.5... = +2.511206(+) = +2.5112060... +1.3... = +1.319720(-) = +1.3197198... -1.1... = -1.194608(+) = -1.1946084... +0.84... = +0.846072(-) = +0.8460715... -0.7... = -0.705696(+) = -0.7056962... Total number of base 10 digits used = 241
For similar examples using unit_exponential_dist and unit_uniform_dist, see sample_exponential.cpp and sample_normal.cpp.
Using discrete_normal_dist, we can similarly obtain the result directly as an int or we can obtain the partial sample i_rand object with represents a uniform range whose size is a power of the base. See sample_discrete_normal.cpp.