static private string Choose(WDict w) { long total = w.Sum(t => t.Value); while (true) { int i = r.Next(0, w.Count); double c = r.NextDouble(); System.Collections.Generic.KeyValuePair <string, uint> k = w.ElementAt(i); if (c < (double)k.Value / total) { return(k.Key); } } }