Creates a random string of characters

@param   string  the type of string
@param   int     the number of characters
@return  string  the random string
336201
public static function random($type = 'alnum', $length = 16) {
        switch ($type) {
            case 'basic':
                return mt_rand();
                break;

            default:
            case 'alnum':
            case 'numeric':
            case 'nozero':
            case 'alpha':
            case 'distinct':
            case 'hexdec':
                switch ($type) {
                    case 'alpha':
                        $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                        break;

                    default:
                    case 'alnum':
                        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                        break;

                    case 'numeric':
                        $pool = '0123456789';
                        break;

                    case 'nozero':
                        $pool = '123456789';
                        break;

                    case 'distinct':
                        $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
                        break;

                    case 'hexdec':
                        $pool = '0123456789abcdef';
                        break;
                }

                $str = '';
                for ($i = 0; $i < $length; $i++) {
                    $str .= substr($pool, mt_rand(0, strlen($pool) - 1), 1);
                }
                return $str;
                break;

            case 'unique':
                return md5(uniqid(mt_rand()));
                break;

            case 'sha1' :
                return sha1(uniqid(mt_rand(), true));
                break;

            case 'uuid':
                $pool = array('8', '9', 'a', 'b');
                return sprintf('%s-%s-4%s-%s%s-%s', static::random('hexdec', 8), static::random('hexdec', 4), static::random('hexdec', 3), $pool[array_rand($pool)], static::random('hexdec', 3), static::random('hexdec', 12));
                break;
        }
    }
840286
private function randomString()
    {
        $chars  = 'qazxswedcvfrtgbnhyujmkiolp1234567890QAZXSWEDCVFRTGBNHYUJMKIOLP';
        $max    = $this->length_random_string;
        $size   = strlen($chars) - 1;
        $string = '';

        while ($max--) {
            $string .= $chars[mt_rand(0, $size)];
        }

        return $string;
    }
1372997
public static final String generateHex(final Random random, final int characters)
	{
		if (characters < 1)
			throw new IllegalArgumentException("characters must be >= 1");

		final char[] str = new char[characters];

		for (int i = 0; i < characters; i++)
		{
			str[i] = hex[random.nextInt(16)];
		}

		return new String(str);
	}
862458
public function generateRandomString($length)
    {
        do {
            $bytes = base64_encode($this->random->nextBytes($length));
            $string = substr(strtr($bytes, array('+' => '', '/' => '', '=' => '')), 0, $length);
        } while (strlen($string) < $length);
        return $string;
    }
1232624
public static function GenerateRandomString(int $length = 20)
    {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }
177621
public static String random(int count, RandomType randomType) {
		if (count == 0) return "";
		if (count < 0) {
			throw new IllegalArgumentException("Requested random string length " + count + " is less than 0.");
		}
		char[] buffer = new char[count];
		for (int i = 0; i < count; i++) {
			if (randomType.equals(RandomType.INT)) {
				buffer[i] = _INT.charAt(RANDOM.nextInt(_INT.length()));
			} else if (randomType.equals(RandomType.STRING)) {
				buffer[i] = _STR.charAt(RANDOM.nextInt(_STR.length()));
			}else {
				buffer[i] = _ALL.charAt(RANDOM.nextInt(_ALL.length()));
			}
		}
		return new String(buffer);
	}
522397
function randomString (length) {
    length = length || 6;

    var result = [],
        i;

    for (i = 0; i < length; i++) {
        result[i] = ASCII_SOURCE[(Math.random() * ASCII_SOURCE_LENGTH) | 0];
    }

    return result.join(EMPTY);
}
1248067
public static function random($length = 32, $type = self::RAND_ALL)
    {
        $string = '';
        // todo: make to helper?
        foreach (static::$dictionary as $pos => $item)
        {
            $key = (1 << $pos);
            if ($type >= $key)
            {
                $string .= $item;
                $type   -= $key;
            }
        }

        if (empty($string))
        {
            throw new Exceptions\Blank("Invalid random string type [{$type}].");
        }

        return static::rand($string, $length);
    }
176066
public static String randomString(int len, Random random) {
        if (len < 1) {
            return "";
        }
        int start = ' ';
        int end = 'z' + 1;

        StringBuffer buffer = new StringBuffer();
        int gap = end - start;

        while (len-- != 0) {
            char ch;
            ch = (char) (random.nextInt(gap) + start);

            if (Character.isLetterOrDigit(ch)) {
                buffer.append(ch);
            } else {
                len++;
            }
        }
        return buffer.toString();
    }
627991
def random_chars(number):
    """"""
    char_map = {
        k: v for k, v in chars.CHARS.iteritems()
        if not format_character(k).startswith('\\x')
    }

    char_num = sum(char_map.values())
    return (
        format_character(nth_char(char_map, random.randint(0, char_num - 1)))
        for _ in xrange(0, number)
    )
228328
public static function get_random_string($length = 10, $chars)
	{
	    $random_string = '';
	    
	    for($i = 0; $i < $length; $i++)
	    {
	        $index = rand(0, strlen($chars) - 1);
	        $random_string .= $chars{$index};
	    }
	    
	    return $random_string;
	}
776856
public static String random(int len) {
        final char[] chars = {'0', '1', '2', '3', '4',
                '5', '6', '7', '8', '9', '$', '#', '^', '&', '_',
                'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
                'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
                'u', 'v', 'w', 'x', 'y', 'z',
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
                'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
                'U', 'V', 'W', 'X', 'Y', 'Z',
                '~', '!', '@'};

        final int max = chars.length;
        Random r = new Random();
        StringBuilder sb = new StringBuilder(len);
        while(len-- > 0) {
            int i = r.nextInt(max);
            sb.append(chars[i]);
        }
        return sb.toString();
    }
1255134
public static function randomFor($char)
    {
        $list = self::listForCharacter($char);
        $class = get_called_class();
            
        return new $class($list[rand(0, count($list) - 1)]);

    }
1010726
public static String generateRandomKey (Random rand, int length)
    {
        int numKeyChars = KEY_CHARS.length();
        StringBuilder buf = new StringBuilder();
        for (int ii = 0; ii < length; ii++) {
            buf.append(KEY_CHARS.charAt(rand.nextInt(numKeyChars)));
        }
        return buf.toString();
    }
267356
protected static function generateRandomString($length)
    {
        $characters = static::CHARACTERS;

        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }

        return $randomString;
    }
1096163
public static String randomString(int length) {
        Preconditions.checkArgument(length > MIN_PASSWORD_LENGTH, "random string length must be at least 1 character");
        Preconditions.checkArgument(length <= MAX_PASSWORD_LENGTH, "random string length must be at most 256 character");
        
        return RandomStringUtils.random(length, 0, CHARACTERS.length-1, false, false, CHARACTERS, new SecureRandom());
    }
649381
public static function generateRandomAlphaNumericString($length) {
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $size = strlen($chars);

        $randomChars = array();
        for ($i = 0; $i < $length; $i++) {
            $randomChars[] = $chars[mt_rand(0, $size - 1)];
        }

        return implode('', $randomChars);
    }