Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no need to use the <code>variate_generator</code> and both code samples are fine.</p> <p>The variate_generator is just there for convenience, such that you don't need to call <code>norm_dist(rng)</code> with the <code>rng</code> argument every time you need a new number.</p> <p>If you construct a <code>variate_generator&lt;mt19937&amp;, normal_distribution&lt;double&gt; &gt; normal_distr_rnd_num</code>, you can just call <code>normal_distr_rnd_num()</code> each time you want to get a new number. This may make the code more readable in some cases.</p> <p>I'm not sure what you are trying to do with the <code>SampleNormal(double mean, double sigma)</code> function. If you call the function very often with the very same values for <code>(mean,sigma)</code> it might be worth to construct such a variate_generator object - let's call it <code>sample_normal</code> - and then just call <code>sample_normal()</code> instead of your function.</p> <p><br/></p> <p>A comment on the quality of the numbers:<br/> The quality of the numbers depends mostly on the underlying pseudo random number algorithm, i.e. the generator you choose. mt19337 has a period of 2^19937-1, which should suffice for 10^7 = 2^24(roughly) numbers, and no "obvious" correlation between two consecutive numbers. However, the numbers are still produced by a single deterministic algorithm. It is possible, however unlikely, that your application might be just the test to prove this determinism. So you could also vary the pseudo random number generator to see if your application gives the same results with an entirely different way of generating pseudo random numbers.</p> <p>I'm more concerned about the initialization (seeding) of the generators. If you run 100 instances, it is tempting to do this in parallel. Now, if you run some of them in parallel, two instances may start at the same time. Since you initialize the generator with <code>time()</code>, these two instances will be seeded with the very same number. Hence both instances will use the exact same sequence of random numbers.</p> <p>In scientific applications it is good practice to either manually seed the random number generator (to ensure they were initialized with different seeds) or to at least record/log the used seed. This way you are able to reproduce the sequence of pseudo random numbers and therefore the result of your program.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload