I need to create batches of randomly generated usernames and passwords.
To start off, I have:

 $validuchars='abcdefghijkmnopqrstuvwxyz';
 $validpchars='abcdefghijkmnopqrstuvwxyz23456789';
 $lenu=strlen($validuchars)-1;
 $lenp=strlen($validpchars)-1;

The first method I came up with was:

 $uid=''; for($i=8;$i;$i--) $uid.=substr($validchars,mt_rand(0,$lenu),1);
 $pwd=''; for($i=8;$i;$i--) $pwd.=substr($validchars,mt_rand(0,$lenp),1);

But I'm wondering if there's any significant benefit to this instead:

 for( $uid=''; strlen($uid)<8; $uid.=substr($validuchars,mt_rand(0,$lenu),1) );
 for( $pwd=''; strlen($pwd)<8; $pwd.=substr($validpchars,mt_rand(0,$lenp),1) );

I can't see any difference in speed.  Does the savings of the $i variable
have any signficance at all?

Another thing I was thinking of doing was making more pronouncable
usernames with something like:

 $cons="bcdfghjklmnpqrstvwxyz";
 $vowels="aeiouy";
 $lenv=strlen($vowels)-1;
 $lenc=strlen($cons)-1;
 $uid=""; for($i=4;$i;$i--)
  $uid.=substr($cons,mt_rand(0,$lenc),1) . substr($vowels,mt_rand(0,$lenv),1);

Any thoughts?

Incidentally, I'm guaranteeing uniqueness of usernames with a unique
index in the MySQL table that stores this stuff.  Including the INSERT,
I can create about 100000 of these in 60 seconds.  So this is more a
question of style than of practical limitations.  ;)

-- 
  Paul Chvostek                                             <[EMAIL PROTECTED]>
  Operations / Abuse / Whatever                          +1 416 598-0000
  it.canada - hosting and development                  http://www.it.ca/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to