src/Random.php
public function getRandomString($length, $charset = null)
    {
        $length = (int) $length;
        if (!$charset) {
            $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
        }

        $charsetLength = strlen($charset);
        $neededBytes = $this->getBytesInBits($length * ($this->getBitsInInteger($charsetLength) + 1));

        $string = '';
        do {
            $byteString = $this->generator->generate($neededBytes);
            for ($i = 0; $i < $neededBytes; ++$i) {
                if (ord($byteString[$i]) > (255 - (255 % $charsetLength))) {
                    continue;
                }
                $string .= $charset[ord($byteString[$i]) % $charsetLength];
            }
        } while (strlen($string) < $length);

        return substr($string, 0, $length);
    }
public function getRandomString($length, $charset = null)
    {
        $length = (int) $length;
        if (!$charset) {
            $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
        }

        $charsetLength = strlen($charset);
        $neededBytes = $this->getBytesInBits($length * ($this->getBitsInInteger($charsetLength) + 1));

        $string = '';
        do {
            $byteString = $this->generator->generate($neededBytes);
            for ($i = 0; $i < $neededBytes; ++$i) {
                if (ord($byteString[$i]) > (255 - (255 % $charsetLength))) {
                    continue;
                }
                $string .= $charset[ord($byteString[$i]) % $charsetLength];
            }
        } while (strlen($string) < $length);

        return substr($string, 0, $length);
    }
Get a random string of the specified length.

@param  integer $length The length of the requested string.
@return string  A random string of the specified length, consisting of
characters from the base64 character set.