PHP Random String

Cara Membuat Generate Random String Number :

//length : panjang dari string yang akan di generate
function generateRandomStringNumber($length = 8) {

    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double) microtime() * 1000000);
    $i = 0;
    $pass = '';
    $calcLength = $length - 1;
    while ($i <= $calcLength) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }

    return strtoupper($pass);
}
echo generateRandomStringNumber(8);
//result : 6Yssha87 or ....
Share This Post: