fromCharset static method

String fromCharset(
  1. int length,
  2. String charset
)

Generates a random string from a custom charset.

Implementation

static String fromCharset(int length, String charset) {
  if (charset.isEmpty) {
    throw ArgumentError('charset cannot be empty');
  }
  final rand = math.Random();
  return List.generate(length, (_) => charset[rand.nextInt(charset.length)]).join('');
}