title: Percentage Based Probability
body: <p>I have this code snippet:</p>
  
  <pre><code>Random rand = new Random();
  int chance = rand.Next(1, 101);
  
  if (chance &lt;= 25) // probability of 25%
  {
      Console.WriteLine("You win");
  }
  else
  {
      Console.WriteLine("You lose");
  }
  </code></pre>
  
  <p>My question is, does it really calculate a 25% probability for winning here?
  Is the chance of winning for the player here is really 25%?</p>
  
  <p>Edit:</p>
  
  <p>I just wrote this:</p>
  
  <pre><code>        double total = 0;
          double prob = 0;
          Random rnd = new Random();
          for (int i = 0; i &lt; 100; i++)
          {
              double chance = rnd.Next(1, 101);
              if (chance &lt;= 25) prob++;
              total++;
          }
          Console.WriteLine(prob / total);
          Console.ReadKey();
  </code></pre>
  
  <p>And it's highly inaccurate. It goes from about 0.15 to 0.3.</p>
  
  <p>But when I do more checks (change from (i &lt; 100) to (i &lt; 10000)) it's much more accurate.</p>
  
  <p>Why is this? Why aren't 100 checks enough for it to be accurate?</p>