Created
April 5, 2017 13:38
-
-
Save fdcore/82ce4b47831bf80d7c24ae5193e0b4fc to your computer and use it in GitHub Desktop.
random chance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// @param $c int шанс выйгрыша | |
function _randc($c){ | |
mt_srand(crc32(microtime())); | |
return (mt_rand(0, 100) < $c); | |
} | |
// test avg random | |
function random_c($c=50){ | |
$win = 0; $fail = 0; | |
for ($i=0; $i < 1000; $i++) { | |
if(_randc($c)){ | |
$win++; | |
} else{ | |
$fail++; | |
} | |
} | |
echo "win: $win / fail: $fail"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment