The beauty of this is that if a length less than 32 is wanted, it will randomly select the position as well.
< ?
function randomString($length)
{
// Generate random 32 charecter string
$string = md5(time());
// Position Limiting
$highest_startpoint = 32-$length;
// Take a random starting point in the randomly
// Generated String, not going any higher then $highest_startpoint
$randomString = substr($string,rand(0,$highest_startpoint),$length);
return $randomString;
}
?>
function randomString($length)
{
// Generate random 32 charecter string
$string = md5(time());
// Position Limiting
$highest_startpoint = 32-$length;
// Take a random starting point in the randomly
// Generated String, not going any higher then $highest_startpoint
$randomString = substr($string,rand(0,$highest_startpoint),$length);
return $randomString;
}
?>
To use the function:
< ?php
// Gets a random string of length 10
$randomString = randomString(10);
?>
// Gets a random string of length 10
$randomString = randomString(10);
?>
This function literally has a statistical chance of repeating the same value next to never. Unless, of course, you only want 1 charecter returned. At that point, their are only 34 different possibilities that it could be (a-z and 0-9). Other then that, it will be pretty unique!
Thats about it! It is pretty self explanitory. Enjoy!
discuss this topic to forum
