> -----Original Message-----
> From: Jason Barnett [mailto:[EMAIL PROTECTED]
> Sent: January 24, 2005 09:41
> To: [email protected]
> Subject: [PHP-WIN] Re: Random
>
>
> SargeTron wrote:
> > "How can I create a random string"
> >
> > rand() only returns an int (number), but I would like something like
> > dd75$6*, you know, containing any character. I would like
> it only to do a
> > certain string ONCE, so there are no duplicates (in a for
> loop). Hopefully I
> > won't need to do a huge array. Any suggestions?
>
> I would suggest uniqid()
> http://www.php.net/manual/en/function.uniqid.php
>
> It creates a random string that is 32 characters long, hopefully this
> will fit your needs?
>
> --
> Teach a man to fish...
>
> NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
> STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
> STFM | http://www.php.net/manual/en/index.php
> STFW | http://www.google.com/search?q=php
> LAZY |
> http://mycroft.mozdev.org/download.html?name=PHP&submitform=Fi
> nd+search+plugins
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Here is a function I found a while back that I use for Random Password creation
##############################################
function str_makerand () {
$minlength = 5;
$maxlength = 10;
$useupper = 1;
$usespecial = 0;
$usenumbers = 1;
/*
Author: Peter Mugane Kionga-Kamau
http://www.pmkmedia.com
Description: string str_makerand(int $minlength, int $maxlength, bool
$useupper, bool $usespecial, bool $usenumbers)
returns a randomly generated string of length between $minlength and
$maxlength inclusively.
Notes:
- If $useupper is true uppercase characters will be used; if false they
will be excluded.
- If $usespecial is true special characters will be used; if false they
will be excluded.
- If $usenumbers is true numerical characters will be used; if false
they will be excluded.
- If $minlength is equal to $maxlength a string of length $maxlength
will be returned.
- Not all special characters are included since they could cause parse
errors with queries.
***********************************************************
* Change Log 11.19.03 *
***********************************************************
aw 11.19.03 Removed zero and alpha O from selection choices
*/
$charset = "abcdefghijklmnopqrstuvwxyz";
if ($useupper) $charset .= "ABCDEFGHIJKLMNPQRSTUVWXYZ";
if ($usenumbers) $charset .= "123456789";
if ($usespecial) $charset .= "[EMAIL PROTECTED]()_+-={}|]["; // Note:
using all special characters this reads: "[EMAIL
PROTECTED]&*()_+`-={}|\\]?[\":;'><,./";
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;
}
###########################################
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php