Philip,
With a few tweaks, it works great, thanks!
Here's what worked:
function randomString($len)
{
global $seed;
$tmp = '';
$chars = 'abcdefghijklmnopqrstuvwxyz';
$chars .= strtoupper($chars);
$chars .= '0123456789';
if (empty($seed)) {
mt_srand ((float) microtime() * 1000000);
$seed = TRUE;
}
// weak error checking mechanism
if ($len < 1 || !intval($len)) $len = 8;
$chars_len = strlen($chars);
for ($a=1; $a <= $len; $a++) {
$tmp .= $chars[mt_rand(0,$chars_len)];
}
return $tmp;
}
Philip Olson wrote:
> Hi Bill,
>
> Here's a quick hack, should get you on your way :
>
> function randomString($len)
> {
> global $seed;
>
> $tmp = '';
>
> $chars = 'abcdefghijklmnopqrstuvwxyz';
> $chars .= strtoupper($chars);
> $chars .= '0123456789';
>
> if (empty($seed)) {
> mt_srand ((float) microtime() * 1000000);
> $seed = TRUE;
> }
>
> // weak error checking mechanism
> if ($len < 1 || !is_numeric($len)) $len = 8;
>
> $chars_len = strlen($chars);
>
> for ($a=1; $a <= $len; $a++) {
> $tmp .= $chars{mt_rand(0,$chars_len)};
> }
>
> return $tmp;
> }
>
> That was fun :)
>
> Regards,
> Philip Olson
>
> On Sat, 1 Sep 2001, bill wrote:
>
> > How can a random string of only letters and numbers be generated?
> >
> > I'm stumped so far on how to avoid including symbols.
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]