Generador de cadenas aleatorias PHP
function generateRandomString($length = 25) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
//usage
$myRandomString = generateRandomString(5);
cadena aleatoria de php
function rand_str() {
$characters = '0123456789-=+{}[]:;@#~.?/>,<|\!"£$%^&*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomstr = '';
for ($i = 0; $i < random_int(50, 100); $i++) {
$randomstr .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomstr;
}
randomstring php
//generates 13 character random unique alphanumeric id
echo uniqid();
//output - 5e6d873a4f597
Generar Cadena aleatoria en PHP
phpCopy<?php
$Random_str = uniqid();
echo "Random String:", $Random_str, "\n";
?>
Generar Cadena aleatoria en PHP
phpCopy<?php
echo "Output-1: ",bin2hex(random_bytes(10)),"\n";
echo "Output-2: ",bin2hex(random_bytes(20)),"\n";
echo "Output-3: ",bin2hex(random_bytes(24)),"\n";
?>