diff --git a/app/Http/helpers.php b/app/Http/helpers.php new file mode 100644 index 0000000..505ce94 --- /dev/null +++ b/app/Http/helpers.php @@ -0,0 +1,21 @@ + 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; +} diff --git a/composer.json b/composer.json index daf183f..99480c8 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,9 @@ "phpunit/phpunit": "^7.0" }, "autoload": { + "files": [ + "app/Http/helpers.php" + ], "classmap": [ "database/seeds", "database/factories"