Generate random string.

The generated string is safe to be used as filename
@param len
@return a random string with specified length
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();
    }
328073
function (len) {
            var result = '';
            if (len) {
                result = this.source.substr(this.position, len);
            } else {
                result = this.source.substr(this.position);
            }
            return result;
        }
1064760
def random_string(length):
    
    valid_chars = string_ascii_letters + string_digits

    return ''.join(random.choice(valid_chars) for i in range(length))
17451
public static String randomAsciiFixLength(Random random, int length) {
		return RandomStringUtils.random(length, 32, 127, false, false, null, random);
	}
288203
def _make_random_string(length):
    
    chars = string.ascii_lowercase + string.ascii_uppercase + string.digits
    return ''.join(random.choice(chars) for x in range(length))
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();
    }
479983
public function randomStr($len = 20, $ignore = null)
    {
        $source = 'abcdefghikjlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
        if (!is_null($ignore)) {
            $tmp = array();
            for ($i = 0; $i < strlen($ignore); ++$i) {
                $tmp[] = $ignore[$i];
            }
            $source = str_replace($tmp, '', $source);
        }
        $len = abs(intval($len));
        $n = strlen($source) - 1;
        $ret = '';
        for ($i = 0; $i < $len; ++$i) {
            $ret .= $source[rand(0, $n)];
        }

        return $ret;
    }
101593
public static String randomAsciiRandomLength(int minLength, int maxLength) {
		return RandomStringUtils.random(nextInt(minLength, maxLength), 32, 127, false, false, null,
				threadLocalRandom());
	}
1316119
public static String rand(int size) {
        StringBuilder num = new StringBuilder();
        for (int i = 0; i < size; i++) {
            double a = Math.random() * 9;
            a = Math.ceil(a);
            int randomNum = new Double(a).intValue();
            num.append(randomNum);
        }
        return num.toString();
    }
873775
def random_string(len)
      rand_max = RAND_CHARS.bytesize
      ret = ""
      len.times{ ret << RAND_CHARS[rand(rand_max)] }
      ret
    end
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')
357470
function rand16Num(len) {
    let result = [];
    for (let i = 0; i < len; i++) {
        result.push('0123456789abcdef'.charAt(
            Math.floor(Math.random() * 16))
        );
    }
    return result.join('');
}
331271
def random(length, chars=None):
    
    if chars is None:
        chars = string.ascii_letters + string.digits
    else:
        ensure_string(chars)
        if not chars:
            raise ValueError("character set must not be empty")

    if is_pair(length):
        length = randint(*length)
    elif isinstance(length, Integral):
        if not length > 0:
            raise ValueError(
                "random string length must be positive (got %r)" % (length,))
    else:
        raise TypeError("random string length must be an integer; "
                        "got '%s'" % type(length).__name__)

    return join(chars.__class__(), (choice(chars) for _ in xrange(length)))
1006080
function randomFileOrFolderName(len = 32) {
  if (Number.isFinite(len)) {
    return crypto.randomBytes(Math.ceil(len / 2)).toString('hex').slice(0, len);
  }
  throw new Error(`illegal argument: ${len}`);
}
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);
	}
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());
    }
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);
    }