generateRandomString method

String generateRandomString(
  1. int length, {
  2. bool includeUppercase = true,
  3. bool includeNumber = true,
})

Implementation

String generateRandomString(int length,
    {final bool includeUppercase = true, final bool includeNumber = true}) {
  if (length <= 0) {
    length = generateRandomInt(minimum: 1);
  }
  final StringBuffer buffer = StringBuffer();
  for (int index = 0; index < length; index++) {
    if (_random.nextBool()) {
      buffer
          .write(_generateRandomAlphabet(includeUppercase: includeUppercase));
    } else if (includeNumber) {
      buffer.write(generateRandomInt());
    } else {
      buffer
          .write(_generateRandomAlphabet(includeUppercase: includeUppercase));
    }
  }
  return buffer.toString();
}