title: How to obtain a random sample from a categorical distribution using Matlab's rand()?
body: <p>I want to generate samples according to a simple categorical probability distribution, e.g.</p>
  
  <pre><code>p(A) = 0.1
  p(B) = 0.5
  p(C) = 0.25
  p(D) = 0.15
  </code></pre>
  
  <p>Using rand(), which uniformly generates samples in (0,1] what is the best way to achieve this?</p>