nextAsciiString method

String nextAsciiString(
  1. int length, {
  2. List<Range<int>> ranges = const [],
  3. List<Range<int>> excludedRanges = const [],
})

Generates a String containing randomly generated ASCII characters uniformly distributed in the provided ranges.

If ranges is empty, then AsciiRanges.upperLetters will be used.

See ASCII Table

Implementation

String nextAsciiString(
  int length, {
  List<Range<int>> ranges = const [],
  List<Range<int>> excludedRanges = const [],
}) {
  // Do not assign put [defaultRange] directly into the default list
  // value for the [ranges] parameter, because then the user could
  // provide an empty list for [ranges] and [_nextAsciiStringFromRanges]
  // will then be called without a single range.
  const defaultRange = AsciiRanges.upperLetters;

  return _nextAsciiStringFromRanges(
    length: length,
    excludedRanges: excludedRanges,
    ranges: [
      ...ranges,
      if (ranges.isEmpty) defaultRange,
    ],
  );
}