Voodoo\Core\Helpers::generateRandomString PHP Method

generateRandomString() public static method

Can also generate a random number by providing the minLen and randomLen=true
Author: : Mardix
public static generateRandomString ( INT $strLen = 7, INT $minLen = 5, BOOL $randomLen = false, BOOL $noCloseSameChar = true, $addZeroOne = false ) : STRING
$strLen INT : the maximum length of the new string
$minLen INT : The minimum length to generate the $randomLen
$randomLen BOOL : to generate random length between $strLen and $minLen
$noCloseSameChar BOOL : If you don't want two same chars to be close to each other
$addZeroOne
return STRING : a new length of string
    public static function generateRandomString($strLen = 7, $minLen = 5, $randomLen = false, $noCloseSameChar = true, $addZeroOne = false)
    {
        // Alpha: valid chars. Numbers: 0 and 1 are removed since the look like i and o and capital letters
        $alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz23456789";
        $chars = $alpha . ($addZeroOne ? "01_" : "");
        $charsLen = strlen($chars);
        $strLen = $randomLen == true ? rand($minLen, $strLen) : $strLen;
        $newStr = $aplha[rand(0, strlen($alpha) - 1)];
        for ($i = 1; $i < $strLen; $i = strlen($newStr)) {
            $r = $chars[rand(0, $charsLen)];
            $newStr .= $noCloseSameChar ? strtolower($r) != strtolower($newStr[$i - 1]) ? $r : "" : $r;
        }
        return $newStr;
    }