Random number generation seeding in C++ I wrote a small function to return a random in a given range:

int random_in_range(int min, int max) {
    std::random_device rd;
    std::mt19937 rng(rd());
    std::uniform_int_distribution&lt;int&gt; uni(min, max);
    return uni(rng);
}


But I read somewhere that you should only seed a random number generator once leading me to believe that the function should really be:

std::random_device rd;
std::mt19937 rng(rd());
int random_in_range(int min, int max) {
    std::uniform_int_distribution&lt;int&gt; uni(min, max);
    return uni(rng);
}


I later tested both to see if one was clearly better than the other (in terms of randomness) and got results which do not make things any clearer.

First example result with 10 runs, making a decision of 1 or 0:

for (int i = 0; i &lt; 10; i++) {
    cout &lt;&lt; first_example(0, 1);
}
&gt;0100100001


The second example result with 10 runs, making a decision of 1 or 0:

 for (int i = 0; i &lt; 10; i++) {
    cout &lt;&lt; second_example(0, 1);
}
&gt;1011000110


The two results don't seem too strange leading me to be confused about how I should initialize random number generators.
Basically, what I am asking is: which of these two example (or something else if both are wrong) would be used in order to guarantee the lowest amount of bias?
Here's how Bjarne Stroustrup did it:

// random number generator from Stroustrup: 
// http://www.stroustrup.com/C++11FAQ.html#std-random
int rand_int(int low, int high)
{
    static std::default_random_engine re {};
    using Dist = std::uniform_int_distribution&lt;int&gt;;
    static Dist uid {};
    return uid(re, Dist::param_type{low,high});
}


The principal difference is that the random engine re is static so there is only one initialization (and therefore seed).  

Also note that a sample of 10 runs is too short to conclude much. Testing random number generators (RNGs) or psuedo-random number generators (PRNGs) is quite complex.  See http://csrc.nist.gov/groups/ST/toolkit/rng/index.html for a thorough explanation of the purpose, theory and actual source-code for tools to do a good job of testing PRNGs.