generateRandomString static method

String generateRandomString({
  1. required int length,
  2. required String characters,
  3. required Random random,
})

Generates a random string from the provided characters.

length: The length of the string. characters: The character set to use. random: The Random instance for generating indices. Returns a random string of specified length.

Implementation

static String generateRandomString({
  required int length,
  required String characters,
  required Random random,
}) {
  final codeUnits = List.generate(
    length,
    (_) => characters.codeUnitAt(random.nextInt(characters.length)),
  );
  return String.fromCharCodes(codeUnits);
}