Answers for "generate 4 digit random string in php"

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
0

Generate Random String in 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";
 
?>
Posted by: Guest on April-23-2021

Code answers related to "generate 4 digit random string in php"

Browse Popular Code Answers by Language