title: Lottery algorithm - PHP - math seems good, but is the function valid?
body: <p>I want to make a custom lottery extraction to motivate users to participate in an online experiment. The rules are: </p>
  
  <ul>
  <li>10% to get 10$</li>
  <li>1% chance to get 50$</li>
  <li>0.1% chance to get 500$</li>
  </ul>
  
  <p>The lottery is a PHP function that gets called once and returns the prize (0, 10, 50 or 500). I created the function below, and after 70 000 trials the statistics are:</p>
  
  <ul>
  <li>9.11% for 10$</li>
  <li>.91% for 50$</li>
  <li>.01% for 500$</li>
  </ul>
  
  <p>Should I be worried about the algorithm? Is there a better way to create a good distribution of chances than mt_rand ?</p>
  
  <pre><code>function lottery() {
    // winnings before extraction
    $win=0;
  
    // choose a winning number between 1 and 10
    $target=mt_rand(1,10);
  
    // make three independent extractions, each with 1/10 probability
    if (mt_rand(1,10) == $target) {
      // if first extraction is the winning number -&gt; prize=10
      // probability: 1/10
      $win=10;
  
      if (mt_rand(1,10) == $target) {
          // if second extraction is ALSO the winning number -&gt; prize=50
          // probability: 1/10 * 1/10
          $win=50;
  
          if (mt_rand(1,10) == $target) {
              // if third extraction is ALSO the winning number -&gt; prize=500
              // probability: 1/10 * 1/10 * 1/10
              $win=500;
          }
      }
    }
    // return the prize
    return $win;
  }
  </code></pre>
  
  <p>Thank you for helping a newbie!</p>