Created
August 31, 2017 07:29
-
-
Save fxm90/07cbecc7f9ae96c63ba34b55a34d8c39 to your computer and use it in GitHub Desktop.
PHP - Random helper functions
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
// Returns a random float value between "$min" and "$max". | |
// Usage: $latitude = randomFloat(53.394655, 53.694865) | |
function randomFloat($min, $max) { | |
return $min + lcg_value() * abs($max - $min); | |
} | |
// Returns a random argument, passed to this function. | |
// Usage: $fruit = randomArgument('Apple', 'Banana', 'Strawberry'); | |
function randomArgument() { | |
$numberOfArguments = func_num_args(); | |
$randomArgument = mt_rand(0, $numberOfArguments - 1); | |
return func_get_arg($randomArgument); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment