randomString method

String randomString(
  1. int length, {
  2. bool includeNumbers = true,
  3. bool includeSymbols = false,
})

Implementation

String randomString(
  int length, {
  bool includeNumbers = true,
  bool includeSymbols = false,
}) {
  const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  const numbers = '0123456789';
  const symbols = '!@#\$%^&*()_+-=[]{}|;:,.<>?';

  String chars = letters;
  if (includeNumbers) chars += numbers;
  if (includeSymbols) chars += symbols;

  return String.fromCharCodes(Iterable.generate(
      length, (_) => chars.codeUnitAt(_random.nextInt(chars.length))));
}