Return a random string of the given length from the
    given character set.

    :param int length: The length of string to return
    :param str charset: A string of characters to choose from
    :returns: A random string
    :rtype: str
765029
def random_string(length, charset):
    
    n = len(charset)
    return ''.join(charset[random.randrange(n)] for _ in range(length))
1265676
private static Charset getCharset(String charset)
    {
        try
        {
            return Charset.forName(charset);
        }
        catch (final UnsupportedCharsetException exception)
        {
            Verbose.exception(exception);
            return Charset.defaultCharset();
        }
    }
17451
public static String randomAsciiFixLength(Random random, int length) {
		return RandomStringUtils.random(length, 32, 127, false, false, null, random);
	}
164131
def _create_secret(self, length=12):
        
        # Charset will have 64 +- characters
        charset = string.digits + string.ascii_letters + '+-'
        return "".join(random.SystemRandom().choice(charset) for _ in
                range(length))
1235800
def rand_unicode(min_char=MIN_UNICHR, max_char=MAX_UNICHR, min_len=MIN_STRLEN,
                 max_len=MAX_STRLEN, **kwargs):
    '''
    '''
    from syn.five import unichr
    return unicode(rand_str(min_char, max_char, min_len, max_len, unichr))
514312
def randstr(self):
        
        return gen_rand_str(
            4, 10, use=self.random, keyspace=list(string.ascii_letters))
1373291
public static String randomString(int length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = (int) random(0, ALL_CHAR.length() - 1);
            sb.append(ALL_CHAR.charAt(index));
        }
        return sb.toString();
    }
238435
def rand_str(max_len=6):
    
    v = [x for x in NUM_LETTER_STR]
    np.random.shuffle(v)
    return ''.join(v[:max_len])
442149
def rand_str(allowed, length):
    
    if (not isinstance(length, int)) or (length <= 0):
        raise Exception("length parameter has to be an integer greater than 0!")
    
    res = list()
    for _ in range(length):
        res.append(random.choice(allowed))
    return "".join(res)
862847
def create_random_string(length=7, chars='ABCDEFGHJKMNPQRSTUVWXYZ23456789',
                         repetitions=False):
    
    if repetitions:
        return ''.join(random.choice(chars) for _ in range(length))
    return ''.join(random.sample(chars, length))
1204522
def randomString(length, chrs=None):
    """"""
    if chrs is None:
        return getBytes(length)
    else:
        n = len(chrs)
        return ''.join([chrs[randrange(n)] for _ in xrange(length)])
419938
def get_rand_string(length=12, allowed_chars='0123456789abcdef'):
    
    if not using_sysrandom:
        # This is ugly, and a hack, but it makes things better than
        # the alternative of predictability. This re-seeds the PRNG
        # using a value that is hard for an attacker to predict, every
        # time a random string is required. This may change the
        # properties of the chosen random sequence slightly, but this
        # is better than absolute predictability.
        random.seed(
            hashlib.sha256(
                ("%s%s" % (
                    random.getstate(),
                    time.time())).encode('utf-8')
            ).digest())
    return ''.join([random.choice(allowed_chars) for i in range(length)])
66330
def generate_random_string(length=6):
    '''
    
    '''
    n = int(length / 2 + 1)
    x = binascii.hexlify(os.urandom(n))
    s = x[:length]
    return s.decode('utf-8')
1219053
public static String getRandomAlphaNumeric(int length) {
        if (length <= 0) {
            return "";
        }

        Random r = getRandom();

        StringBuffer result = new StringBuffer(length);

        for (int i = 0; i < length; i++) {
            int n = r.nextInt(alphaNumChars.length);
            result.append(alphaNumChars[n]);
        }

        return result.toString();
    }
622864
def random(self, length=None):
        
        if length is None:
            length = self._length

        random_num = int(binascii.b2a_hex(os.urandom(length)), 16)
        return int_to_string(random_num, self._alphabet, padding=length)[:length]
628142
def _get_random_string(length=44,
                       allowed_chars='abcdefghijklmnopqrstuvwxyz'
                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
                       secret_key=settings.secret_key_bytes()):
    
    secret_key = _ensure_bytes(secret_key)
    _reseed_if_needed(using_sysrandom, secret_key)
    return ''.join(random.choice(allowed_chars) for i in range(length))
1058702
def gen_random_string(str_len):
    
    return ''.join(
        random.choice(string.ascii_letters + string.digits) for _ in range(str_len))