/ Published in: PHP

Here is an example where the likelihood of NS is 30%, SM is 50%, and SH is 20%. I make 20 pitches and output what the batter does each time.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $percentNS = 0.3; $percentSM = 0.5; $percentSH = 1.0 - $percentNS - $percentSM; $upperBoundNS = $percentNS; $upperBoundSM = $percentNS + $percentSM; $upperBoundSH = 1.0; for ($i = 0; $i < 20; $i++) { $rand = $rand / 100.0; if ($rand < $upperBoundNS) { echo 'not swing'; } else if ($rand < $upperBoundSM) { echo 'swing and miss'; } else { // $rand < $upperBoundSH echo 'swing and hit'; } echo '<br />'; } ?>
URL: http://www.kirupa.com/forum/showthread.php?t=344243
Comments
