string static method

String string(
  1. int length, {
  2. String? pool,
})

Returns a string of random characters.

Enter the length parameter to specify the length of the returned string.

Enter the pool parameter to specify the list of characters that the method will return. For example, if pool == 'abcde', asciiString will a random String composed of a, b, c, d, or e.

Implementation

static String string(int length, {String? pool}) {
  var poolList = ascii;
  if (pool != null) {
    poolList = utf8.encode(pool);
  }
  var chars = List.generate(length, (int i) {
    return random.nextInt(94);
  });
  var ret = <int>[];
  for (var x in chars) {
    ret.add(poolList[x]);
  }
  return utf8.decode(ret);
}