Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.