title: How to use boost::uniform_on_sphere?
body: <p>I am trying to pick a random point on a unit sphere, and found that boost provides the distribution that does exactly this. But when I try to use it, all generated values are <code>nan</code>. I don't know what I am doing wrong, could you please enlighten me? This small code depicts what I am trying to do:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  #include &lt;boost/random/mersenne_twister.hpp&gt;
  #include &lt;boost/random/uniform_on_sphere.hpp&gt;
  
  int main()
  {
    boost::mt19937 gen;
    boost::uniform_on_sphere&lt;float&gt; dist(3);
  
    { // Seed from system random device
      std::ifstream rand_device("/dev/urandom");
      uint32_t seed;
      rand_device &gt;&gt; seed;
  
      gen.seed(seed);
    }
  
    while(1) {
      // Generate a point on a unit sphere
      std::vector&lt;float&gt; res = dist(gen);
  
      // Print the coordinates
      for(int i = 0; i &lt; res.size(); ++i) {
        std::cout &lt;&lt; res[i] &lt;&lt; ' ';
      }
      std::cout &lt;&lt; '\n';
    }
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>nan nan nan 
  nan nan nan 
  nan nan nan 
  nan nan nan 
  </code></pre>
  
  <p>ad infinitum...</p>