Created
January 16, 2022 16:48
-
-
Save gugadev/62072374e711ddbfe9674f5989589771 to your computer and use it in GitHub Desktop.
Create random alphanumeric string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Courtesy of https://stackoverflow.com/a/61929967/10670707 | |
Future<String> genRandomAlphanumeric(int length) async { | |
const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890'; | |
Random _rnd = Random(); | |
return String.fromCharCodes( | |
Iterable.generate( | |
length, | |
(_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length)) | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment