PHP 7 has a function called random_bytes that you use by converting from binary to hex, generates a string similar to what you want.
<?php
// Usando a função random_bytes do PHP 7
for ($x = 1; $x <= 10; $x++)
{
echo bin2hex(random_bytes(3)) . "<br>"; // gera uma string pseudo-randômica criptograficamente segura de 6 caracteres
}
?>
Output example (changes every time you run the script):
eb5a35
ce5121
d5c514
e4eec4
48d781
52367c
ae39cd
5ef0ff
dfe681
0ac13f
Reference:
link
But if you still do not use PHP7 or you did not like the hexadecimal option used by the existing function in PHP7, an interesting technique I saw in Stack Overflow in English and adapted here is using str_shuffle , a function that shuffles strings randomly. This function is present in PHP from PHP 4 .
<?php
// Usando str_shuffle (mistura strings aleatoriamente)
for ($x = 1; $x <= 10; $x++)
{
//Inclua todos os caracteres que gostaria que aparecessem nas strings geradas
$caracteres_q_farao_parte = 'abcdefghijklmnopqrstuvwxyz0123456789';
$password = substr( str_shuffle($caracteres_q_farao_parte), 0, 6 );
echo $password . "<br>";
}
?>
Output example (will come out different every time the script is run):
yc7dj6
g57rt0
prwgdn
hctvog
d2l0cq
r78fp1
0z6c4e
95m8fa
19bnx5
vyw8p6
Reference: link