randomAlphaNumericString static method

String randomAlphaNumericString(
  1. int length
)

Generates a random alphanumeric string of the specified length.

Implementation

static String randomAlphaNumericString(int length) {
  const chars =
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  final random = Random();
  return String.fromCharCodes(
    Iterable.generate(
      length,
      (_) => chars.codeUnitAt(random.nextInt(chars.length)),
    ),
  );
}