Selecting Random Item from List given probability of each item
<p>Sorry about badly phrased title....</p>

<p>I have an object called NGram</p>

<pre><code>class NGram
{
     //other properties
     double Probability {get; set;} //Value between 1 and 0 
}
</code></pre>

<p>Now suppose I have a list of these objects such that...</p>

<pre><code>List&lt;NGrams&gt; grams = GetNGrams();
Debug.Assert(grams.Sum(x =&gt; x.Probability) == 1);
</code></pre>

<p>How can I select a random item from this list while factoring in the probability distribution.</p>

<p>For instance, suppose <code>grams[0].Probability == 0.5</code> then there should be a 50% chance of selecting <code>grams[0]</code> </p>

<p>I figured I may need something like  <code>rand.NextDouble()</code> but I am at loss.</p>