Jump to content

Generating random letters and numbers ?


jd2007

Recommended Posts

I always do something like this when creating a string of a certain length comprised of certain characters:

 

//Length of the random string
$length = 8;

//Specify which characters you want in your string. Here it's letters (a-z)
$characters = range(a-z);

//Create the string with a while loop
$i = 1;
while($i <= $length) {
  $string .= $characters[rand(0,count($characters))];
  $i++;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.