Generates a string of the given length from the given set of characters

@param {Array} set An Array of decimal characters
@param {Integer} length The length of the string to generate
@returns {String} The random generated string
962872
function generateString(set, length) {
    var content = '';

    // Cannot generate a string from an empty set
    if (set.length <= 0) {
      return content;
    }

    for (var i = 0; i < length; i++) {
      content += String.fromCharCode(
        set[Math.floor(Math.random() * set.length)]
      );
    }

    return content;
  }
447050
public static function randomString(int $length, $characters = null): string
    {
        if (is_null($characters)) {
            $characters = array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9'));
        }
        if (is_string($characters)) {
            $characters = str_split($characters);
        }
        $result = '';
        $characterCount = count($characters);
        for ($i = 0; $i < $length; ++$i) {
            $result .= $characters[self::randomInt(0, $characterCount - 1)];
        }
        return $result;
    }
1225139
def generate(length):
    """"""
    if not isinstance(length, int) or length < 2:
        raise TypeError('length must be a positive integer greater than 1.')

    # first digit cannot be 0
    digits = [random.randint(1, 9)]

    for i in range(length-2):
        digits.append(random.randint(0, 9))
    digits.append(get_check_digit(''.join(map(str, digits))))

    return ''.join(map(str, digits))
411777
function (len, min, chars) {
      len = len || 10;
      if (min != undefined) {
        len = publicRuleMethods._num(len, min);
      }
      var i;
      var str = '';
      chars = chars || ALPHA_NUMERIC_CHARS;
      var charsCount = chars.length;
      for (i = 0; i < len; i++) {
        str += chars[Math.floor(Math.random() * charsCount)];
      }
      return str;
    }
593457
function(length) {
      var bytes, hex;
      if (length == null) {
        length = 32;
      }
      length /= 2;
      bytes = this.randomBytes(length);
      return hex = this.toHex(bytes).toUpperCase();
    }
245174
function random(length, options) {
  length || (length = 8);
  options || (options = {});

  var chars = '';
  var result = '';

  if (options === true) {
    chars = numbers + letters + specials;
  } else if (typeof options == 'string') {
    chars = options;
  } else {
    if (options.numbers !== false) {
      chars += (typeof options.numbers == 'string') ? options.numbers : numbers;
    }

    if (options.letters !== false) {
      chars += (typeof options.letters == 'string') ? options.letters : letters;
    }

    if (options.specials) {
      chars += (typeof options.specials == 'string') ? options.specials : specials;
    }
  }

  while (length > 0) {
    length--;
    result += chars[Math.floor(Math.random() * chars.length)];
  }
  return result;
}
995354
private function generateToken($length)
    {
        $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"§$%&/()=[]{}';

        $useChars = array();
        // select some random chars:
        for ($i = 0; $i < $length; $i++) {
            $useChars[] = $characters[mt_rand(0, strlen($characters) - 1)];
        }
        // Add numbers
        array_push($useChars, rand(0, 9), rand(0, 9), rand(0, 9));
        shuffle($useChars);
        $randomString = trim(implode('', $useChars));
        $randomString = substr($randomString, 0, self::TOKEN_LENGHT);

        return base64_encode($randomString);
    }
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;
    }
259698
public static String randomString(String baseString, int length) {
		final StringBuilder sb = new StringBuilder();

		if (length < 1) {
			length = 1;
		}
		int baseLength = baseString.length();
		for (int i = 0; i < length; i++) {
			int number = getRandom().nextInt(baseLength);
			sb.append(baseString.charAt(number));
		}
		return sb.toString();
	}
546711
function randomEnglishWord (length) {
	var consonants = 'bcdfghjklmnpqrstvwxyz',
		vowels = 'aeiou',
		i, word='',
		consonants = consonants.split(''),
		vowels = vowels.split('');
	for (i=0;i<length/2;i++) {
		var randConsonant = consonants[randomNumber(consonants.length-1)],
			randVowel = vowels[randomNumber(vowels.length-1)];
		//word += (i===0) ? randConsonant.toUpperCase() : randConsonant;
		word += (i===0) ? randConsonant : randConsonant;
		word += i*2<length-1 ? randVowel : '';
	}
	return word;
}
1064760
def random_string(length):
    
    valid_chars = string_ascii_letters + string_digits

    return ''.join(random.choice(valid_chars) for i in range(length))
599538
private static function generateRandomString($length = 10)
    {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $string = '';

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

        return $string;
    }
1138245
def generate_random_string(cls, length):
        
        # avoid things that could be mistaken ex: 'I' and '1'
        letters = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"
        return "".join([random.choice(letters) for _ in range(length)])
1322613
function(length) {
  if(typeof length !== "number") return null;
  if(length < 0) return null;

  let len = [];
  let digit = 0;

  do {
    digit = length % 128 | 0;
    length = length / 128 | 0;
    if (length > 0) {
        digit = digit | 0x80;
    }
    len.push(digit);
  } while (length > 0);

  return len;
}
409126
function random (length) {
  // Guard
  if (length == null) {
    length = DEFAULT;
  } else if (!(typeof length === 'number' && length > 0)) {
    throw new Error('Length should be +ve Number');
  }

  // Fill buffer
  var bits = bitString.randomBits(6 * length);
  return baseURL.encode(bits);
}
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();
    }
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;
}