Всё намного проще
$arr_k = array('Q','W','E','R','T','Y','U','I' ;,'O','P','A','S','D','F','G','H',&# 39;J','K','L','Z','X','C','V','B','N ','M','q','w','e','r','t','y','u' ;,'i','o','p','a','s','d','f','g',&# 39;h','j','k','l','z','x','c','v','b ','n','m','1','2','3','4','5','6' ;,'7','8','9','0');
$k = array_rand($arr_k, mt_rand(10, 15));
$key = '';
foreach($k as $kw) $key .= $arr_k[$kw];