randomString function

String randomString(
  1. int length, {
  2. bool secure = false,
  3. String pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
})

Returns a random String with a set length.

Is cryptographically insecure by default. Set secure to true to utilize Random.secure. You may provide a pool of characters to pick from.

Implementation

String randomString(int length,
    {bool secure = false,
    String pool =
        'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'}) {
  final random = secure ? Random.secure() : _random;
  return List.generate(length, (i) => pool[random.nextInt(pool.length)]).join();
}