generate static method
Implementation
static String generate({int keyLength = 16}) {
const String chars =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!%&+-?@#';
//
Random random = Random();
String key = '';
//
if (keyLength < 1) {
throw Exception('Key length must be greater than 0');
} else if (keyLength > chars.length) {
throw Exception('Key length must be less than 1000');
}
for (int i = 0; i < (keyLength); i++) {
int index = random.nextInt(chars.length);
key += chars[index];
}
return key;
}