generateCode function

String generateCode(
  1. int length, {
  2. int seed = 0,
  3. String charSet = "23456789abcdefghjkmnpqrstuvwxy",
})

Create a code of length length randomly for id.

Characters that are difficult to understand are omitted.

seed can be specified.

Implementation

String generateCode(int length,
    {int seed = 0, String charSet = "23456789abcdefghjkmnpqrstuvwxy"}) {
  final _length = charSet.length;
  final rand = seed != 0 ? Random(seed) : Random();
  final codeUnits = List.generate(
    length,
    (index) {
      final n = rand.nextInt(_length);
      return charSet.codeUnitAt(n);
    },
  );
  return String.fromCharCodes(codeUnits);
}