title: Random numbers with arbitrary probability distribution using rand() only
body: <p>I am looking for a simple algorithm how to generate pseudo-random floating point numbers using only ANSI rand() function but with arbitrary probability distribution. For a simple uniform distribution I use following code:</p>
  
  <pre><code>x = (float)rand() / (float)RAND_MAX;
  </code></pre>
  
  <p>Of course it is not very accurate, but enough for my needs. I need also other distributions like logistic and gaussian. Ideally I have to define an arbitrary pdf using a simple vector of finite length, e.g. for logistic pdf this vector may look like: </p>
  
  <pre><code>logistic_pdf = {0., 0.26894, 0.33924, 0.41742, 0.5, 0.58257, 0.66075, 1.};
  </code></pre>
  
  <p>and for uniform (using same dimensionality 8):</p>
  
  <pre><code>uniform_pdf = {0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125};
  </code></pre>
  
  <p>This is only an idea. But I am not sure how to implement it efficiently using <code>rand()-&gt;{0...RAND_MAX}</code> only.</p>