• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/security/random.php
  • Класс: BitrixMainSecurityRandom
  • Вызов: Random::getStringByArray
static function getStringByArray(int $length, array $charsetList): string
{
	$count = count($charsetList);

	// take strlen() out of the cycle
	$charsets = [];
	foreach ($charsetList as $charset)
	{
		$charsets[] = [$charset, strlen($charset)];
	}

	$randomSequence = static::getBytes($length);

	$result = '';
	for ($i = 0; $i < $length; $i += $count)
	{
		shuffle($charsets);

		for ($j = 0; $j < $count; $j++)
		{
			$randomNumber = ord($randomSequence[$i + $j]);

			$charset = $charsets[$j][0];
			$charsetVariants = $charsets[$j][1];
			$result .= $charset[$randomNumber % $charsetVariants];

			if (($i + $j + 1) == $length)
			{
				break 2;
			}
		}
	}

	return $result;
}