Re: creating random strings without md5

From: Date: Tue, 07 May 2002 19:49:03 +0000
Subject: Re: creating random strings without md5
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-19027@lists.php.net to get a copy of this message
thanx Ryan. did give me the right idea. Andy "Ryan Jameson" <RJameson@usa.ibs.org> schrieb im Newsbeitrag news:CC8578B824E74940BA5126774F49628D0F9D70@NATHAN.ibs.org... BTW... I just noticed the code doesn't exactly match the description. Hmmm... so shoot me. :-) <>< Ryan -----Original Message----- From: Ryan Jameson (USA) Sent: Tuesday, May 07, 2002 1:11 PM To: php-db@lists.php.net Subject: RE: [PHP-DB] creating random strings without md5 That should be quite easy, just take the ascii integer range you want for instance 65-90 are all the capital letters, generate a random number using rand, then mod it by the number in the range in this case 26, then add 65 to it and use chr() to turn it into a character. Put this all in a function called randChr or something... you can get more creative and use conditions to use different clusters of characters and such? Didn't think so how's this: <?PHP function randChr($max){ $add = 65; //65 is the 'A' $val = rand(time,$max); $val = $val + $add; return chr($val); } function randChrString($len){ $retVal = ""; $shift = 25; for($i=0;$i<$len;$i++) $retVal .= randChr($shift); return $retVal; } echo "Here ya go: " . randChrString(255); ?> Make sense? <>< Ryan -----Original Message----- From: andy [mailto:news.letters@gmx.de] Sent: Tuesday, May 07, 2002 12:30 PM To: php-db@lists.php.net Subject: [PHP-DB] creating random strings without md5 Hi there, I did create random strings with md5 because I did not know a better way. But it takes to long, and I guess that function is not made for it :-) So is there a function which is creating random characters like mt_rand or rand() does for numbers? I would like to create a string up to 255 characters long with random characters. Thanx for any help, Andy -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.db (#19027) next »