Answers for "php get random letter"

PHP
28

PHP random string generator

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);
Posted by: Guest on October-30-2019
0

Generate Random String in PHP

phpCopy<?php
 
function secure_random_string($length) {
    $rand_string = '';
    for($i = 0; $i < $length; $i++) {
        $number = random_int(0, 36);
        $character = base_convert($number, 10, 36);
        $rand_string .= $character;
    }
 
    return $rand_string;
}
 
echo "Sec_Out_1: ",secure_random_string(10),"\n";
 
echo  "Sec_Out_2: ",secure_random_string(10),"\n";
 
echo  "Sec_Out_3: ",secure_random_string(10),"\n";
 
?>
Posted by: Guest on April-23-2021

Browse Popular Code Answers by Language