Generate a random ID
26
This is a simple function to generate a random ID of letters and numbers however long you want. All you do is pass it how many parts you want and then how many pieces(chars/numbers) per part you want.
I hope you enjoy
I hope you enjoy
/** FUNCTION: generate_ID
*
* This function generates a random ID of letters and numbers
* as long as is desired.
*
* @ARGUMENTS: 2
* - $np: This determines how many parts are randomly
* generated. Some parts will be numbers and
* some will be letters.
* - $npp: This is the number of pieces-per-part. Each
* part is made up of multiple pieces
* @RETURNS:
* - $id: The randomly Generated ID
**/
function generate_ID($np,$npp)
{
// The id to create
$id = "";
// Create an array of characters
$aplha = "a b c d e f g h i j k l m n o p q r s t u v w x y z";
$aplha = explode(" ", $aplha);
for ($j = 0; $j < $np; $j++)
{
$r = rand(1,2);
for ($i = 0; $i < $npp; $i++)
{
if ($r == 1)
{
// Generate random numbers
$id .= rand(1,9);
}
else
{
// Generate random letters
$a = rand(1,26);
$id .= $aplha[$a];
}
}
}
return $id;
}





http://www.bytemycode.com/snippets/snippet/579/
For example:
generate_ID(2,3)
generateId(6) (your code)
El buen pupilo es aquel que supera al Maestro.