Skip to content

Instantly share code, notes, and snippets.

@gugadev
Created January 16, 2022 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugadev/62072374e711ddbfe9674f5989589771 to your computer and use it in GitHub Desktop.
Save gugadev/62072374e711ddbfe9674f5989589771 to your computer and use it in GitHub Desktop.
Create random alphanumeric string
/// 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