PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fird01
Forum Newbie
Posts: 19 Joined: Mon Apr 07, 2008 11:04 pm
Post
by fird01 » Sun Apr 27, 2008 9:14 pm
what does this coding means..?
Code: Select all
if ($minlength > $maxlength) $length = mt_rand ($maxlength, $minlength);
else $length = mt_rand ($minlength, $maxlength);
for ($i=0; $i<$length; $i++) $key .= $charset[(mt_rand(0,(strlen($charset)-1)))];
return $key;
especially this one
Code: Select all
$charset[(mt_rand(0,(strlen($charset)-1)))]
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sun Apr 27, 2008 10:57 pm
Code: Select all
$length_of_string_charset = strlen($charset);
$index_of_last_character_in_charset = $length_of_string_charset - 1;
$random_index_in_charset = mt_rand(0, $index_of_last_character_in_charset);
$random_character_in_charset = $charset[$random_index_in_charset];
(#10850)
codeblock
Forum Newbie
Posts: 4 Joined: Sun Apr 27, 2008 5:26 pm
Location: USA
Post
by codeblock » Sun Apr 27, 2008 11:04 pm
fird01 wrote: what does this coding means..?
Code: Select all
if ($minlength > $maxlength) $length = mt_rand ($maxlength, $minlength);
else $length = mt_rand ($minlength, $maxlength);
for ($i=0; $i<$length; $i++) $key .= $charset[(mt_rand(0,(strlen($charset)-1)))];
return $key;
if $minlength is greater than $max length, then $lenth is a random variable between $maxlength and $minlength.
otherwise, $length is a random number between $minlength and $maxlength
especially this one
Code: Select all
$charset[(mt_rand(0,(strlen($charset)-1)))]
That takes everything in an array, and appends it to $key randomely.
and it returns $key