Generar PNRG sin repetirse
Publicado por aprendiz (12 intervenciones) el 12/03/2006 05:41:54
Hola, tengo un script php para generar passwds al azar, tiene un seed de 1.000.000, , tengo k generar ese millon de passwds, pero no se como ya que obviamente tienden a repetirse al ser "Pseudo aleatorias", sé que se puede pero no sé el metodo, ya intente generando un archivo de mas de 2 millones y luego pasarlo por un programa que borrara los duplicados (duplifind), pero ademas del tiempo k gasta, tan solo llego a los 960.435, tb use el array unique, pero es muy lento!(aunque si funciona) aqui les dejo el codigo, y si alguien tuviera otro metodo y me lo pudiera decir se los agradeceria mucho
<?php
$z = 1;
while ($z <= 100000) {
$z++;
$chars = array('A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j','K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0');
$max_chars = count($chars) - 1;
srand( (double) microtime()*1000000);
$rand_str = '';
for($i = 0; $i < 8; $i++)
{
$rand_str = ( $i == 0 ) ? $chars[rand(0, $max_chars)] : $rand_str . $chars[rand(0, $max_chars)];
}
$help = md5($rand_str);
$help2 = substr($help, 0, 6);
$file = "ackkey5.txt";
$handle = fopen($file, "a") or die("could not open file for writing");
fwrite($handle, "$help2\n");
$text = file($file) or die("could not read file");
$unique = array_unique($text);
foreach($unique as $line)
{
fwrite($handle, $line);
}
}
?>
<?php
$z = 1;
while ($z <= 100000) {
$z++;
$chars = array('A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j','K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0');
$max_chars = count($chars) - 1;
srand( (double) microtime()*1000000);
$rand_str = '';
for($i = 0; $i < 8; $i++)
{
$rand_str = ( $i == 0 ) ? $chars[rand(0, $max_chars)] : $rand_str . $chars[rand(0, $max_chars)];
}
$help = md5($rand_str);
$help2 = substr($help, 0, 6);
$file = "ackkey5.txt";
$handle = fopen($file, "a") or die("could not open file for writing");
fwrite($handle, "$help2\n");
$text = file($file) or die("could not read file");
$unique = array_unique($text);
foreach($unique as $line)
{
fwrite($handle, $line);
}
}
?>
Valora esta pregunta


0