generateToken static method

String generateToken({
  1. int length = 50,
})

Implementation

static String generateToken({int length: 50}) {
  var r0 = Random();
  var buffer = StringBuffer();
  for (int i = 1; i <= length; i++) {
    var r = Random(r0.nextInt(0x70000000) + (DateTime.now()).millisecondsSinceEpoch);
    if (r.nextBool()) {
      String letter = alphabet[r.nextInt(alphabet.length)];
      buffer.write(r.nextBool() ? letter.toLowerCase() : letter);
    } else {
      buffer.write(numbers[r.nextInt(numbers.length)]);
    }
  }
  return buffer.toString();
}