title: Generating many, good, uniformly distributed random numbers
body: <p>I am running analyses on very large graphs with random weights. I know that using the <code>rand()</code> function is poor, so I have been using this function based on what I have read to be proper random number generation:</p>
  
  <pre><code>double randomZeroToOne()
  {
      random_device rd;
      mt19937 mt(rd());
      uniform_real_distribution&lt;double&gt; dist(0.0, 1.0);
      double randomRealBetweenZeroAndOne = dist(mt);
      return randomRealBetweenZeroAndOne;
  }
  </code></pre>
  
  <p>Everytime I want to put a weight in my graph, I call this function and insert it into my adjacency matrix. However, I am worried that perhaps I am using a slow method to generate these numbers. This has worked fine for small graphs, but my larger graphs are very slow (likely something else is slowing it down, but I just wanted to double check and learn the proper way). What is the best way to preserve the quality of the numbers but to generate them as quickly as possible?</p>
  
  <p>Additionally, if you know a way to initialize a vector of a known size with fast, good, uniformly distributed random numbers, that would be even better (although I am still curious about the answer to my main question).</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This is my new proposed solution:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;random&gt;
  #include&lt;vector&gt;
  #include&lt;iomanip&gt;
  #include&lt;cmath&gt;
  using namespace std;
  
  random_device rd;
  mt19937 mt(rd());
  uniform_real_distribution&lt;double&gt; dist(0.0, 1.0);
  
  int main()
  {
      double randomRealBetweenZeroAndOne = dist(mt);
      double anotherRandomRealBetweenZeroAndOne = dist(mt);
      double anothernother = dist(mt);
      vector&lt;double&gt; randoman(10,dist(mt));
      cout &lt;&lt; randomRealBetweenZeroAndOne &lt;&lt; endl;
      cout &lt;&lt; anotherRandomRealBetweenZeroAndOne &lt;&lt;endl;
      cout &lt;&lt; anothernother &lt;&lt;endl;
  }
  </code></pre>
  
  <p>Please let me know if you see any issues with this, especially if this function will be called many times.</p>