Generate random string using openssl_random_pseudo_bytes(). It'll return all possible English lower
and uppercase letters with numbers, not just hexadecimal string

@param int $length

@return string
@throws Exception
192900
public static function randomString(int $length): string
    {
        $random = '';
        $passes = 0;

        do {
            foreach (str_split(openssl_random_pseudo_bytes($length * 3)) as $c) {
                $ascii = ord($c);

                if ($ascii >= 48 && $ascii <= 57 || $ascii >= 65 && $ascii <= 90 || $ascii >= 97 && $ascii <= 122) {
                    $random .= chr($ascii);
                }
            }
        } while (strlen($random) < $length && $passes++ < 50);

        if ($passes == 50) {
            throw new Exception('Unable to generate random string even after a lot passes... something is really wrong!');
        }

        return substr($random, 0, $length);
    }
773025
public function genRandomPassword($length = 8) {

        $salt     = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $base     = strlen($salt);
        $makepass = '';

        /*
         * Start with a cryptographic strength random string, then convert it to
         * a string with the numeric base of the salt.
         * Shift the base conversion on each character so the character
         * distribution is even, and randomize the start shift so it's not
         * predictable.
         */
        $random = Crypt::genRandomBytes($length + 1);
        $shift  = ord($random[0]);

        for ($i = 1; $i <= $length; ++$i) {
            $makepass .= $salt[($shift + ord($random[$i])) % $base];
            $shift += ord($random[$i]);
        }

        return $makepass;
    }
1017997
public static function getRandomString(int $length = 64) : string
    {
        $characters = "01234567890123456789";
        $characters .= "abcdefghijklmnopqrstuvwxyz";

        $string_generated = "";

        while ($length--) {
            $string_generated .= $characters[mt_rand(0, 45)];
        }

        return $string_generated;
    }
1079061
public static function generate($length=128) {

        if ($length < 32) {

            return substr(self::getUid(), 0, $length);

        } else if ($length == 32) {

            return self::getUid();

        }  else {

            $numString = (int)($length/32) + 1;
            $randNum = "";
            for ($i = 0; $i < $numString; $i++) $randNum .= self::getUid();

            return substr($randNum, 0, $length);

        }

    }
673061
private static function generateBytes($length)
    {
        $bytes = '';
        for ($i = 1; $i <= $length; $i++) {
            $bytes = \chr(\mt_rand(0, 255)) . $bytes;
        }

        return $bytes;
    }
1026204
static public function randomString( $length ) {
      $transactionhars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
      $size = strlen( $transactionhars );
      $str = '';
      for( $i = 0; $i < $length; $i++ )
        $str .= $transactionhars[ rand( 0, $size - 1 ) ];

      return $str;
  }
404018
public function read($length = 1)
    {

        if (($length + $this->index) > $this->length) {
            throw new Exception("Unable to read length={$length} from buffer.  Bad protocol format or return?");
        }

        $string = substr($this->data, $this->index, $length);
        $this->index += $length;

        return $string;
    }
958601
public static function int_rand($length,$one='')
    {
        $str = self::random_pseudo_bytes(32,10,$one);
        $strlen = strlen($str)-1;
        $results = '';
        for($i=1;$i<=$length;$i++){
            $results  .= $str{mt_rand(0,$strlen)};
        }


        return $results;
    }
653185
protected function generateNonce( $length = 32 )
    {
        $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $result = '';
        for ( $i = 0; $i < $length; $i++ )
        {
            $result .= $chars[mt_rand( 0, strlen( $chars ) - 1 )];
        }

        return $result;
    }
1146271
public function generateSecret($length = 10)
	{
		$strong_secret = false;

		// Try to get $crypto_strong to evaluate to true. Give it 5 tries.
		for ($i = 0; $i < 5; $i++)
		{
			$secret = openssl_random_pseudo_bytes($length, $strong_secret);

			if ($strong_secret === true)
			{
				return $this->base32->encode($secret);
			}
		}

		return '';
	}
604866
public function generateRandomString(int $length = 32): string
    {
        if ($length < 1) {
            throw new \RuntimeException('First parameter ($length) must be greater than 0');
        }

        $bytes = $this->generateRandomKey($length);
        return \substr(StringHelper::base64UrlEncode($bytes), 0, $length);
    }
995263
public static function random_string($length) {
        $key = '';
        $keys = array_merge(range(0, 9), range('a', 'z'));

        for ($i = 0; $i < $length; $i++) {
            $key .= $keys[array_rand($keys)];
        }

        return $key;
    }
985638
public function generateString($length)
    {
        $cryptoStrong = false;
        //Create Binary String
        $binaryString = openssl_random_pseudo_bytes($length, $cryptoStrong);

        //Unable to create binary string
        if ($binaryString === false) {
            throw new DropboxClientException(static::ERROR_MESSAGE . 'openssl_random_pseudo_bytes() returned an unknown error.');
        }

        //Binary String is not cryptographically strong
        if ($cryptoStrong !== true) {
            throw new DropboxClientException(static::ERROR_MESSAGE . 'openssl_random_pseudo_bytes() returned a pseudo-random string but it was not cryptographically secure and cannot be used.');
        }

        //Convert binary to hex
        return $this->binToHex($binaryString, $length);
    }
32539
static public function randomCaseString($length=32)
    {
        $pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
        
        return substr(str_shuffle(str_repeat($pool, ceil($length / strlen($pool)))), 0, $length);
        
        return static::random($length, 0, true);
    }
1168638
public static function readableRandomString($length = 8)
    {
        $conso = [
            'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'
        ];
        $vocal = ['a', 'e', 'i', 'o', 'u'];

        $word = '';
        srand((double) microtime() * 1000000);
        $max = $length / 2;

        for ($i = 1; $i <= $max; ++$i) {
            $word .= $conso[rand(0, 19)];
            $word .= $vocal[rand(0, 4)];
        }
        return $word;
    }
772823
public static function random_bytes($length, $raw = false)
    {
        $hextab  = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $tabsize = strlen($hextab);

        // Use PHP7 true random generator
        if ($raw && function_exists('random_bytes')) {
            return random_bytes($length);
        }

        if (!$raw && function_exists('random_int')) {
            $result = '';
            while ($length-- > 0) {
                $result .= $hextab[random_int(0, $tabsize - 1)];
            }

            return $result;
        }

        $random = openssl_random_pseudo_bytes($length);

        if ($random === false && $length > 0) {
            throw new Exception("Failed to get random bytes");
        }

        if (!$raw) {
            for ($x = 0; $x < $length; $x++) {
                $random[$x] = $hextab[ord($random[$x]) % $tabsize];
            }
        }

        return $random;
    }
730283
public static function random62($length)
    {
        $str = self::DIGIT.self::ALPHABET;
        
        $strLength = 62;
        while($length > $strLength){
            $str .= $str;
            $strLength += 60;
        }
        
        $str = str_shuffle($str);
        return substr($str, 0,$length);
    }