Added helper function file and updated composer.json accordingly.

This commit is contained in:
Lukas Halbritter
2018-09-12 11:07:42 +02:00
parent 6ff2da68ed
commit fcc59f16ae
2 changed files with 24 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
<?php
/*
* Returns true with a given percentage.
*
* @param int $prob Probability for true in percent.
*
* @return boolean
*/
function rand_bool($prob = 50) {
if ($prob < 0 or $prob > 100) {
throw new InvalidArgumentException('The value for the probability '.
' must be in a range from 0 to 100.');
} else if (!is_int($prob)) {
throw new InvalidArgumentException('rand_bool only accepts integers.');
}
$rand = rand(1, 100);
return $rand <= $prob;
}