# Posted By

_reydin_ on 06/22/12

# Statistics

Viewed 979 times
Favorited by 1 user(s)

# Php Random String Generator

/ Published in: PHP
`<? \$l='a';					//Set the starting letterfor(\$i=0;\$i<26;\$i++){	//Cycle through all of the letters of the alphabet a-z	\$key[\$i]=\$l;		//Load the array with lowercase variables at position \$i	\$l++;				//Increment the letter}for(\$x=0;\$x<5;\$x++){	//Cycle through this five times. The more you cycle through this loop the more likely a number will appear.	for(\$n=0;\$n<10;\$n++){	//Cycle through the numbers 0-9		\$key[\$i]=\$n;	//Load the array with number variables at position \$i		\$i++;			//Increment the array key	}}\$u='A';					//Set the starting letterfor(\$c=0;\$c<26;\$c++){	//Cycle through all of the letters of the alphabet A-Z	\$key[\$i]=\$u;		//Load the array with uppercase variables	\$i++;				//Increment the array key	\$u++;				//Increment the letter} \$i--;	//Subtract the last incrementation of \$i because it's not indexed \$str='';for(\$strlength=0;\$strlength<20;\$strlength++){	//Generate the random string 20 characters long	//\$r = rand(0,\$i);	//Generate a random number from the available \$i interger	\$r = rand()&\$i;		//Generate a random number from the available \$i interger using bitwise	\$str .= \$key[\$r];	//Concatenate the random variable} echo \$str;	//Show the random string?>`