Here's a little test to separate the serious coders from the cut-and-paste script kiddies. Given the need to generate an arbitrarily long string consisting of random alpha-numeric characters, which solution is best?
http://zaemis.blogspot.de/2009/10/pop-quiz.html (http://zaemis.blogspot.de/2009/10/pop-quiz.html)
Have fun :lol:
lol
Since I learned programming way back around 1980-ish then a good programmer use as less as and to make it as fast as possible.
Nowadays that has changed to make it reuasable and more readable.
Even creating loads of extra lines.
My solution would be somtehing like:
function randomString($len,$chars) {
$rndMax = strlen($chars) - 1;
$str = "";
while ($len-- != 0) {
$str .= $chars[rand(0, $rndMax)];
}
return $str;
}
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" .
"abcdefghijklmnopqrstuvwxyz" .
"0123456789";
$str = randomString(8,$chars);
echo "$str\n";
Maybe adding some checks to set defaults.
Oh and if I neede this once I think I could do without the function as well ;)
John
or maybe use :
include ("filename.php");
:lol:
Wo wir schon mal beim kürzen sind:
function randomString($len,$char) {
for ($p = 0; $p < $len; $p++) $string .= $char[rand(0, strlen($char)-1)];
return $string;
}