public static function random(
        $count,
        $startPosition = 0,
        $endPosition = 0,
        $letters = true,
        $numbers = true,
        array $characters = array()
    ) {
        if (0 === $count) {
            return StringUtils::EMPTY_STR;
        }

        if (0 > $count) {
            throw new InvalidArgumentException(
                'Requested random string length ' . $count . ' is less than 0.'
            );
        }

        foreach ($characters as $intValue) {
            if (false === CharUtils::isAscii($intValue)) {
                throw new InvalidArgumentException(
                    'Requested set of characters does not contain characters only.'
                );
            }
        }

        if (false === \is_int($startPosition)) {
            $startPosition = CharUtils::fromAsciiCharToValue($startPosition);
        }

        if (false === \is_int($endPosition)) {
            $endPosition = CharUtils::fromAsciiCharToValue($endPosition);
        }

        if (0 > $startPosition) {
            throw new InvalidArgumentException(
                'Requested start position ' . $startPosition . ' is less than 0.'
            );
        }
        if (0 > $endPosition) {
            throw new InvalidArgumentException(
                'Requested end position ' . $endPosition . ' is less than 0.'
            );
        }

        if ((0 === $startPosition) && (0 === $endPosition)) {
            $startPosition = 32;
            $endPosition = 123;

            if ((false === $letters) && (false === $numbers)) {
                $characters = \array_values(
                    \array_diff(
                        CharUtils::charAsciiPrintableArray(),
                        CharUtils::charAsciiAlphanumericArray()
                    )
                );
            }
        }

        $charactersUpperBound = (\count($characters) - 1);
        $result = '';

        while (0 !== $count--) {
            if (!$characters) {
                $intValue = \rand($startPosition, $endPosition);
            } else {
                $intValue = CharUtils::fromAsciiCharToValue(
                    $characters[\rand(0, $charactersUpperBound)]
                );
            }

            $charValue = CharUtils::fromAsciiValueToChar($intValue);

            if ((true === $letters) && (true === CharUtils::isAsciiAlpha($charValue))
                || (true === $numbers) && (true === CharUtils::isAsciiNumeric($charValue))
                || (false === $letters) && (false === $numbers)
            ) {
                $result .= $charValue;
            } else {
                ++$count;
            }
        }

        return $result;
    }