当我从“有效字符数组”生成一个字符数组时,最终结果是一组随机字符但是IN ORDER。例如,我将获得34579abopxzBCJMSTXY。
include('db.php');
//$num= mt_rand();
$veces = $_POST['veces'];
$equipos = $_POST['equipos'];
$description = $_POST['description'];
$salt = "oijahsfdapsf80efdjnsdjp";
function get_result(){
$valid_chars=array("0","1", "2", "3", "4", "5", "6", "7", "8", "9"
, "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
, "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
$result=array_rand($valid_chars, 20); //Cantidad de Caracteres
$result_str='';
foreach ($result as $value)
{
$result_str.=$valid_chars[$value];
}
return $result_str;
}
$results=array();
for ($i=0; $i<=2000; $i++)
{
array_push($results, get_result());
}
$results=array_unique($results);
$cont=0;
$results_str='';
foreach ($results as $value)
{
$cont++;
$results_str.=$value.'
';
// Add some salt
$salt = "oijahsfdapsf80efdjnsdjp";
$salt .= $value; //oijahsfdapsf80efdjnsdjp_Plus_RandomString
$value = $salt; //Change the RandomString to contain our new salted pass
$value = md5($value); //( cannot be reversed on a rainbow table as we have a secret salt also.. )
$db = new Database();
$ins_query = "INSERT INTO licensing(license, computers, state, description) VALUES('{$value}', '{$equipos}', '2', '{$description}')"; // query to insert value
$db->query($ins_query);
if ($cont>=$veces)
{
break;
}
}
echo '<pre>';
echo $results_str;
echo '</pre>';
PHP信息版本5.3.3
输出示例:
1389adehtvwCEKMNQSUY
15bgmnpruwzAEFHTUVWY
159bcenqrswxzFKMNQUX
35bchstvwxyzEGKNQSUV
124789defgmvyDEHKNRT
5abefhjprsuwxCDMPQXY
答案 0 :(得分:2)
您可以使用shuffle(array)
变量上的valid_char
随机化所有元素
http://fr.php.net/manual/en/function.shuffle.php
答案 1 :(得分:1)
$valid_chars=array("0","1", "2", "3", "4", "5", "6", "7", "8", "9"
, "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
, "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
$result=array_rand($valid_chars, 20);
$i=0;
foreach ($result as $value)
{
$result[$i]=$valid_chars[$value];
$i++;
}
foreach ($result as $v) {
echo "$v";
}
echo "<br>";
shuffle($result);
foreach ($result as $v) {
echo "$v";
}
这将回应
0128acfknqrsxCJMPQRS //your string in "order"
PrMxR0k8nqJCQcS2sfa1