title: C# weighted random numbers
body: <p>I need help with the programming of a game.</p>
  
  <p>You open a chest and with a given probability you find an item.</p>
  
  <p>Item / Chance</p>
  
  <p>A / 10%<br>
  B / 30%<br>
  C / 60%</p>
  
  <pre><code>Random random = new Random();
  int x = random.Next(1, 101);
  
  if (x &lt; 11) // Numbers 1..10 ( A -&gt; 10% )
  { 
       do_something1(); d
  } 
  else if (x &lt; 41) // Numbers 11..40 ( B -&gt; 30 % )
  { 
       do_something2();
  }
  else if (x &lt; 101) // Numbers 41..100 ( C -&gt; 60 % ) 
  { 
       do_something3();
  }
  </code></pre>
  
  <p>Does this example really make sense, in terms of probability?
  Do you have another solution?</p>
  
  <p>Thank you in advance!</p>