Skip to content

Instantly share code, notes, and snippets.

@fxm90
Created August 31, 2017 07:29
Show Gist options
  • Save fxm90/07cbecc7f9ae96c63ba34b55a34d8c39 to your computer and use it in GitHub Desktop.
Save fxm90/07cbecc7f9ae96c63ba34b55a34d8c39 to your computer and use it in GitHub Desktop.
PHP - Random helper functions
// 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