randomString method
String
randomString(
- int length, {
- bool includeNumbers = true,
- bool includeSymbols = false,
})
Implementation
String randomString(
int length, {
bool includeNumbers = true,
bool includeSymbols = false,
}) {
const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const numbers = '0123456789';
const symbols = '!@#\$%^&*()_+-=[]{}|;:,.<>?';
String chars = letters;
if (includeNumbers) chars += numbers;
if (includeSymbols) chars += symbols;
return String.fromCharCodes(Iterable.generate(
length, (_) => chars.codeUnitAt(_random.nextInt(chars.length))));
}