summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2011-09-07 06:13:08 +0200
committerDerek Jones <derek.jones@ellislab.com>2011-09-07 06:13:08 +0200
commit32020e61bb311a071ed6dd8b583e83ebc8b98b08 (patch)
tree426ddb4d08eb9f2574c34198d018ab36d3b74501
parent40d1a7684444f6a8eb4cda23d8822f0b258f0c3e (diff)
parent5feb8bb8c89875224049a44ae988500c532ed6d4 (diff)
Merge pull request #399 from druu/patch-1
Major speed improvement in function random_string()
-rw-r--r--system/helpers/string_helper.php9
-rw-r--r--user_guide/changelog.html1
2 files changed, 4 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' :
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index fb6e4493a..cdbbe6bda 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -77,6 +77,7 @@ Change Log
<li>Added <samp>increment_string()</samp> to <a href="helpers/string_helper.html">String Helper</a> to turn "foo" into "foo-1" or "foo-1" into "foo-2".</li>
<li>Altered form helper - made action on form_open_multipart helper function call optional. Fixes (#65)</li>
<li><samp>url_title()</samp> will now trim extra dashes from beginning and end.</li>
+ <li>Improved speed of <a href="helpers/string_helper.html">String Helper</a>'s <b>random_string()</b> method</li>
</ul>
</li>
<li>Database