randomStr static method
指定字符中生成指定长度的随机字符串 prefix前缀
KRandomUtils.randomStr(prefix: "999999") => 999999o6gO4YRfHz6PCpjzA9eYBgWdKH
Implementation
static String randomStr({int length = 32, String? prefix}) {
var len = length - (prefix?.length ?? 0);
final randomStr = List.generate(len,
(index) => _availableChars[_random.nextInt(_availableChars.length)])
.join();
if (prefix.kisNotNull()) {
return "$prefix$randomStr";
} else {
return randomStr;
}
}