背景:需要生成一个随机数作为api参数
实现:
import ‘dart:math‘;
/// dart 生成固定随机数
void main(){
String alphabet = ‘qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM‘;
int strlenght = 30; /// 生成的字符串固定长度
String left = ‘‘;
for (var i = 0; i < strlenght; i++) {
// right = right + (min + (Random().nextInt(max - min))).toString();
left = left + alphabet[Random().nextInt(alphabet.length)];
}
print(left);
}
效果:
原文地址:https://blog.51cto.com/leizhu/2356829
时间: 2024-11-05 17:32:21