1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-05 08:17:47 +02:00

[ticket/10042] Add mt_rand() wrapper which allows swapping $min and $max.

PHPBB3-10042
This commit is contained in:
Andreas Fischer
2011-03-05 22:16:50 +01:00
parent afae883619
commit 5ab4dc2983
2 changed files with 62 additions and 0 deletions

View File

@@ -244,6 +244,22 @@ function unique_id($extra = 'c')
return substr($val, 4, 16);
}
/**
* Wrapper for mt_rand() which allows swapping $min and $max parameters.
*
* PHP does not allow us to swap the order of the arguments for mt_rand() anymore.
* (since PHP 5.3.4, see http://bugs.php.net/46587)
*
* @param int $min Lowest value to be returned
* @param int $max Highest value to be returned
*
* @return int Random integer between $min and $max (or $max and $min)
*/
function phpbb_mt_rand($min, $max)
{
return ($min > $max) ? mt_rand($max, $min) : mt_rand($min, $max);
}
/**
* Return formatted string for filesizes
*