Generates a random password of the specified length with the specified characters.

@param characterTypes the types of characters to include in the password
@param length         the length of the password
@return the password
420991
public static String generateRandomPassword(final CharacterTypes characterTypes, final int length)
    {
        final StringBuffer buffer = new StringBuffer();
        String characters = "";

        switch (characterTypes)
        {

            case ALPHA:
                characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
                break;

            case ALPHANUMERIC:
                characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
                break;

            case ALPHANUMERICSYMBOL:
                characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()";
                break;

            case NUMERIC:
                characters = "1234567890";
                break;
        }

        final int charactersLength = characters.length();
        final SecureRandom rnd = new SecureRandom();

        for (int i = 0; i < length; i++)
        {
            final double index = rnd.nextInt(charactersLength);
            buffer.append(characters.charAt((int) index));
        }
        return buffer.toString();
    }
1171698
protected static function generateCode($length = null, $characters = null)
    {
        $length = (int) ($length ?: config('laravel-sms.verifyCode.length',
            config('laravel-sms.code.length', 5)));
        $characters = (string) ($characters ?: '0123456789');
        $charLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; ++$i) {
            $randomString .= $characters[mt_rand(0, $charLength - 1)];
        }

        return $randomString;
    }
373865
def generate_password(length=16):
    
    chars = string.ascii_letters + string.digits + '!@#$%^&*()_+-=[]{};:,<.>?|'
    modulus = len(chars)
    pchars = os.urandom(16)
    if type(pchars) == str:
        return ''.join(chars[i % modulus] for i in map(ord, pchars))
    else:
        return ''.join(chars[i % modulus] for i in pchars)
574502
public function generateToken($length = 10, $chars = '0123456789abcdefghijklmnopqrstuvwxyz') {
		$token = '';
		$i = 0;
		while ($i < $length) {
			$char = substr($chars, mt_rand(0, strlen($chars) - 1), 1);
			if (!stristr($token, $char)) {
				$token .= $char;
				$i++;
			}
		}

		return $token;
	}
856753
public static function _randomPassword ($length = 10)
	{
		
		// Set random characters variables
		
		$charset		= self::CHARSET_RANDOM;
		
		// Set variables
		
		$charsetLength	= strlen ($charset);
		$password		= NULL;
		
		// Generate Password
		
		for ($i = 0; $i < $length; $i++)
		{
			$password	.= $charset[rand (0, $charsetLength-1)];
		}
		
		// Return password
		
		return $password;
		
	}
1361807
public static function _randomPassword ($length = self::DEFAULT_PASSWORD_LENGTH, $charset = self::DEFAULT_PASSWORD_CHARACTERS)
	{
		
		// Set password variable
		
		$password	= '';

		// Set i to the password length
		
		$i = $length;

		// Loop until the password is the desired length
		
		while ($i > 0)
		{
			
			// Choose a random character from the charset
			
			$char = $charset[mt_rand (0, strlen ($charset) -1)];

			// Make sure that the first character of the password is a number or letter
			
			if ($password == '' && !preg_match('/[0-9A-Za-z]/', $char))
			{
				continue;
			}
			
			// Add the character to the password
			
			$password .= $char;

			// Decrement rounds
			
			$i--;

		}

		// Return the password
		
		return $password;

	}
196111
public static String generateMixPassword(final int n) {
		final char[] pw = new char[n];
		int c = 'A';
		int r1 = 0;
		for (int i = 0; i < n; i++) {
			r1 = (int) (Math.random() * 3);
			switch (r1) {
			case 0:
				c = '0' + (int) (Math.random() * 10);
				break;
			case 1:
				c = 'a' + (int) (Math.random() * 26);
				break;
			case 2:
				c = 'A' + (int) (Math.random() * 26);
				break;
			}
			pw[i] = (char) c;
		}
		return new String(pw);
	}
129277
public String generateRandomToken(int length) {
        final char[] token = new char[length];

        for (int i = 0; i < length; i++) {
            final int tokenIndex = random.nextInt(this.tokenChars.length);
            token[i] = tokenChars[tokenIndex];
        }

        return new String(token);
    }
660830
public static String randomString(int length, @NonNull CharMatcher validChar) {
      return randomString(length, 0, Integer.MAX_VALUE, validChar);
   }
1092872
def make_password(length, chars=string.letters + string.digits + '#$%&!'):
    
    return get_random_string(length, chars)
863716
public static String randomAsciiFixLength(int length) {
		return RandomStringUtils.random(length, 32, 127, false, false, null, threadLocalRandom());
	}
807389
public static String randomString(int length) {
        // CAUSE: If-Else Statements Should Use Braces
        if (length < 1) {
            throw new IllegalArgumentException(String.format("length < 1: %s", length));
        }

		char[] buf = new char[length];

		return nextString(buf);
	}
730926
public static String decorateEncryption(char[] password)
	{
		if(password == null || password.length == 0)
			return null;
		
		return new StringBuilder(ENCRYPTED_PASSWORD_PREFIX)
				.append(encrypt(password)).append(ENCRYPTED_PASSWORD_SUFFIX)
				.toString();

	}
871834
function generateRandomString(length) {
	let s = "";
	let i = length;
	while (length-- > 0) {
		let c = Math.floor(Math.random() * (MAX_HEX_SYMBOL - MIN_HEX_SYMBOL + 1)) + MIN_HEX_SYMBOL;
		c = c.toString(16).toLowerCase();
		s += c;
	}
	return s;
}
294897
def password_generator(length):
    
    return ''.join(random.choice(string.ascii_lowercase + string.digits)
                   for _ in range(length))
921898
public static String captchaChar(int length, boolean caseSensitivity) {
        StringBuilder sb       = new StringBuilder();
        Random        rand     = new Random();// 随机用以下三个随机生成器
        Random        randdata = new Random();
        int           data     = 0;
        for (int i = 0; i < length; i++) {
            int index = rand.nextInt(caseSensitivity ? 3 : 2);
            // 目的是随机选择生成数字，大小写字母
            switch (index) {
                case 0:
                    data = randdata.nextInt(10);// 仅仅会生成0~9, 0~9的ASCII为48~57
                    sb.append(data);
                    break;
                case 1:
                    data = randdata.nextInt(26) + 97;// 保证只会产生ASCII为97~122(a-z)之间的整数,
                    sb.append((char) data);
                    break;
                case 2: // caseSensitivity为true的时候, 才会有大写字母
                    data = randdata.nextInt(26) + 65;// 保证只会产生ASCII为65~90(A~Z)之间的整数
                    sb.append((char) data);
                    break;
                default:
                    break;
            }
        }
        return sb.toString();
    }
694239
def pwgen(length=None):
    """"""
    if length is None:
        # A random length is ok to use a weak PRNG
        length = random.choice(range(35, 45))
    alphanumeric_chars = [
        l for l in (string.ascii_letters + string.digits)
        if l not in 'l0QD1vAEIOUaeiou']
    # Use a crypto-friendly PRNG (e.g. /dev/urandom) for making the
    # actual password
    random_generator = random.SystemRandom()
    random_chars = [
        random_generator.choice(alphanumeric_chars) for _ in range(length)]
    return(''.join(random_chars))