diff options
author | druu <zappa@crushhour.net> | 2011-09-06 21:19:59 +0200 |
---|---|---|
committer | druu <zappa@crushhour.net> | 2011-09-06 21:19:59 +0200 |
commit | 9e2df7c1fc8f8f5c9837f52c308f72e9f326b577 (patch) | |
tree | dda29699f8923581585605bc3ee9c8fe5713e13e /system/helpers/string_helper.php | |
parent | 40d1a7684444f6a8eb4cda23d8822f0b258f0c3e (diff) |
Major speed improvement in function random_string() for cases 'alpha', 'alnum', 'numeric' and 'nozero'
Diffstat (limited to 'system/helpers/string_helper.php')
-rw-r--r-- | system/helpers/string_helper.php | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 9fa69f46c..dd8ffaddb 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -215,12 +215,9 @@ if ( ! function_exists('random_string')) case 'nozero' : $pool = '123456789'; break; } - - $str = ''; - for ($i=0; $i < $len; $i++) - { - $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); - } + + $str = substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len); + return $str; break; case 'unique' : |