You can seed this function with whatever variables you want by adding them to the keyset.  Then you just pass the length to the function and it'll return a random variable based on the keyset and length.

{codecitation}
function r($len){
    $keyset = "abcdefghijklmnopqrstuvwxyz0123456789";
    $randkey = "";
    for ($i=0; $i<$len; $i++)
    {
        $randkey = $randkey . $keyset[mt_rand(0, strlen($keyset)-1)];
    }
    return $randkey;
}{/codecitation}