lib/blobfolio/common/data.php
public static function random_string(int $length=10, $soup=null) {
		if ($length < 1) {
			return '';
		}

		if (\is_array($soup) && \count($soup)) {
			ref\cast::string($soup);

			$soup = \implode('', $soup);
			ref\sanitize::printable($soup);

			$soup = \preg_replace('/\s/u', '', $soup);
			$soup = \array_unique(mb::str_split($soup, 1, true));
			$soup = \array_values($soup);
			if (! \count($soup)) {
				return '';
			}
		}

		// Use default soup.
		if (! \is_array($soup) || ! \count($soup)) {
			$soup = constants::RANDOM_CHARS;
		}

		// Pick nine entries at random.
		$salt = '';
		$max = \count($soup) - 1;
		for ($x = 0; $x < $length; ++$x) {
			$salt .= $soup[static::random_int(0, $max)];
		}

		return $salt;
	}
public static function random_string(int $length=10, $soup=null) {
		if ($length < 1) {
			return '';
		}

		if (\is_array($soup) && \count($soup)) {
			ref\cast::string($soup);

			$soup = \implode('', $soup);
			ref\sanitize::printable($soup);

			$soup = \preg_replace('/\s/u', '', $soup);
			$soup = \array_unique(mb::str_split($soup, 1, true));
			$soup = \array_values($soup);
			if (! \count($soup)) {
				return '';
			}
		}

		// Use default soup.
		if (! \is_array($soup) || ! \count($soup)) {
			$soup = constants::RANDOM_CHARS;
		}

		// Pick nine entries at random.
		$salt = '';
		$max = \count($soup) - 1;
		for ($x = 0; $x < $length; ++$x) {
			$salt .= $soup[static::random_int(0, $max)];
		}

		return $salt;
	}
public static function random_string ( int $ length = 10 , $ soup = null ) { if ( $ length < 1 ) { return '' ; } if ( \ is_array ( $ soup ) && \ count ( $ soup ) ) { ref \ cast :: string ( $ soup ) ; $ soup = \ implode ( '' , $ soup ) ; ref \ sanitize :: printable ( $ soup ) ; $ soup = \ preg_replace ( '/\s/u' , '' , $ soup ) ; $ soup = \ array_unique ( mb :: str_split ( $ soup , 1 , true ) ) ; $ soup = \ array_values ( $ soup ) ; if ( ! \ count ( $ soup ) ) { return '' ; } } // Use default soup. if ( ! \ is_array ( $ soup ) || ! \ count ( $ soup ) ) { $ soup = constants :: RANDOM_CHARS ; } // Pick nine entries at random. $ salt = '' ; $ max = \ count ( $ soup ) - 1 ; for ( $ x = 0 ; $ x < $ length ; ++ $ x ) { $ salt .= $ soup [ static :: random_int ( 0 , $ max ) ] ; } return $ salt ; }
Generate Random String

By default the string will only contain
unambiguous uppercase letters and numbers.
Alternate alphabets can be passed instead.

@param int $length Length.
@param array $soup Alternate alphabet.
@return string Random string.
Generate Random String