[Dart] Generate Random String From [a-z0-9]
import 'dart:core';
import 'dart:math';
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
String RandomString(int strlen) {
Random rnd = new Random(new DateTime.now().millisecondsSinceEpoch);
String result = "";
for (var i = 0; i < strlen; i++) {
result += chars[rnd.nextInt(chars.length)];
}
return result;
}
void main() {
print(RandomString(10));
print(RandomString(20));
}
Tested on: DartPad.
References:
[1] | dart random number - Google search dart random number - DuckDuckGo search dart random number - Bing search dart random number - Yahoo search |
[2] | dart string length - Google search dart string length - DuckDuckGo search dart string length - Bing search dart string length - Yahoo search |
[3] | Language Tour | Dart |