Gererate fixed-length random hexstring, usually for md5.

    :param length: total length of this string.
    :param lower: use lower case or upper case.
348753
def rand_hexstr(length, lower=True):
    
    if lower:
        return rand_str(length, allowed=CHARSET_HEXSTR_LOWER)
    else:
        return rand_str(length, allowed=CHARSET_HEXSTR_UPPER)
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);
	}
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);
}
558987
function generateRandomId (length) {
  var str = ''
  length = length || 6
  while (str.length < length) {
    str += (((1 + Math.random()) * 0x10000) | 0).toString(16)
  }
  return str.substring(str.length - length, str.length)
}
488851
def random(self, length=22):
        
        random_num = int(binascii.b2a_hex(os.urandom(length)), 16)
        return self._num_to_string(random_num, pad_to_length=length)[:length]
381423
def random_str(n=20):
    
    return ''.join(random.sample(string.ascii_letters + string.digits, n))
1201121
def scramble_string(self, length):
        """"""
        return fake.text(length) if length > 5 else ''.join([fake.random_letter() for n in range(0, length)])
583640
def calculate_md5(filename, length):
    
    assert length >= 0

    # shortcut: MD5 of an empty string is 'd41d8cd98f00b204e9800998ecf8427e',
    # represented here in binary
    if length == 0:
        return '\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8\x42\x7e'

    md5_summer = hashlib.md5()

    f = open(filename, 'rb')

    try:
        bytes_read = 0

        while bytes_read < length:
            chunk_size = min(MD5_CHUNK_SIZE, length - bytes_read)

            chunk = f.read(chunk_size)

            if not chunk:
                # found EOF: means length was larger than the file size, or
                # file was truncated while reading -- print warning?
                break

            md5_summer.update(chunk)

            bytes_read += len(chunk)

    finally:
        f.close()

    md5 = md5_summer.digest()

    return md5
1024998
public String randomString(String permitted, int length) {
        StringBuilder result = new StringBuilder(length);
        int maxIndex = permitted.length();
        for (int i = 0; i < length; i++) {
            int index = random(maxIndex);
            char value = permitted.charAt(index);
            result.append(value);
        }
        return result.toString();
    }
1149636
public static String generateDigitsString(int length) {
        StringBuffer buf = new StringBuffer(length);
        SecureRandom rand = new SecureRandom();
        for (int i = 0; i < length; i++) {
            buf.append(rand.nextInt(digits.length));
        }
        return buf.toString();
    }
1263558
function randomString(length, chars) {
  length = length || 8;
  chars = chars || '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  var result = '';
  for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
  return result;
}
1311091
def get_random_value(length=10, character_sets=[string.ascii_uppercase, string.ascii_lowercase]):
        

        return "".join(random.choice("".join(character_sets)) for i in range(length))
673287
def rand_ascii_str(length):
    
    letters = [random.choice(ascii_letters_and_digits) for _ in range(length)]
    return ''.join(letters)
1081284
function md5(src, length) {
    var crypto = require("crypto");
    var hash   = crypto.createHash("md5").update(src, "utf8").digest("hex");
    return hash.slice(0, length);
}
169922
def generate_random_string(length=8):
    
    char_set = string.ascii_uppercase + string.digits
    return ''.join(random.sample(char_set * (length - 1), length))
1143518
def random_token(length=10):
    
    return ''.join(random.choice(string.ascii_uppercase + string.digits)
                   for _ in range(length))
1189629
public static String randomNumberString(int length) {
        char[] chars = "0123456789".toCharArray();
        return RandomStringUtils.random(length, 0, 9, false, false, chars);
    }