randomString function Null safety

String randomString(
  1. int length,
  2. {bool? numbersOnly,
  3. Random? rnd}
)

Implementation

String randomString(int length, {bool? numbersOnly, Random? rnd}) {
  rnd ??= Random(DateTime.now().millisecondsSinceEpoch);
  String result = "";
  final source = numbersOnly == true ? numbers : chars;
  for (var i = 0; i < length; i++) {
    result += source[rnd.nextInt(source.length)];
  }
  return result;
}