From 5940316125c1672b72eb08186e6c43f5a91e71ef Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 9 Apr 2012 13:46:31 +0200 Subject: random_id() -> random_alphanum(); allow single argument Signed-off-by: Florian Pritz --- application/helpers/filebin_helper.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'application/helpers') diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index 3dcd03794..ac09da7d2 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -182,17 +182,21 @@ function is_cli_client() return false; } -function random_id($min_length, $max_length) +function random_alphanum($min_length, $max_length = null) { $random = ''; $char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $char_list .= "abcdefghijklmnopqrstuvwxyz"; $char_list .= "1234567890"; - $length = rand()%($max_length-$min_length) + $min_length; + + if ($max_length === null) { + $max_length = $min_length; + } + $length = mt_rand($min_length, $max_length); for($i = 0; $i < $max_length; $i++) { if (strlen($random) == $length) break; - $random .= substr($char_list,(rand()%(strlen($char_list))), 1); + $random .= substr($char_list, mt_rand(0, strlen($char_list)), 1); } return $random; } -- cgit v1.2.3-24-g4f1b