platform/packages/cli/lib/src/random_string.dart

16 lines
354 B
Dart
Raw Normal View History

2018-07-14 22:47:24 +00:00
import 'dart:math';
const String _valid =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
2021-02-16 02:10:09 +00:00
final Random _rnd = Random.secure();
2018-07-14 22:47:24 +00:00
String randomAlphaNumeric(int length) {
2021-02-16 02:10:09 +00:00
var b = StringBuffer();
2018-07-14 22:47:24 +00:00
for (int i = 0; i < length; i++) {
b.writeCharCode(_valid.codeUnitAt(_rnd.nextInt(_valid.length)));
}
return b.toString();
}