title: How to generate a random number between 0 and 1?
body: <p>I want to generate random numbers between (0,1). I am trying the following:</p>
  
  <pre><code>double r2()
  {
      return((rand() % 10000) / 10000.0);
  }
  
  int SA()
  {
      double u;
      u = r2();
  }
  </code></pre>
  
  <p>But it doesn't generate the expected result. How can I fix it?</p>