“Generador de cadenas aleatorio PHP” Código de respuesta

PHP Generador de cadenas aleatorias

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);
Grepper

PHP Randomstring

//generates 13 character random unique alphanumeric id
echo uniqid();
//output - 5e6d873a4f597
Impossible Ibis

Generar cadena aleatoria en PHP

phpCopy<?php 
$Random_str = uniqid();  
echo "Random String:", $Random_str, "\n";
?> 
CodeGuruDev

Randstring PHP

<?php 
    $random = substr(md5(mt_rand()), 0, 7);
    echo $random;
?>
Mysterious Markhor

Generador de cadenas aleatorio PHP

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

Output the random string with the call below:

// Echo the random string.
// Optionally, you can give it a desired string length.
echo generateRandomString();
Ankur

Generador de cadenas aleatorio PHP

<?php
    function RandomString()
    {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $randstring = '';
        for ($i = 0; $i < 10; $i++) {
            $randstring = $characters[rand(0, strlen($characters))];
        }
        return $randstring;
    }

    RandomString();
    echo $randstring;
Ankur

Respuestas similares a “Generador de cadenas aleatorio PHP”

Preguntas similares a “Generador de cadenas aleatorio PHP”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código