string method

String string(
  1. String chars,
  2. int length
)

Generate random string from specific characters and length.

Implementation

String string(String chars, int length) {
  if (chars.isEmpty) {
    return "";
  }

  Random _rnd = Random();

  return String.fromCharCodes(Iterable.generate(
      length, (_) => chars.codeUnitAt(_rnd.nextInt(chars.length))));
}