我是DART的新手,我想知道有什么方法可以从DART中的给定字符串中选择随机字符。
有内置功能吗?
谢谢
最佳答案
好了,您可以使用Random
中的dart:math
类来实现自己的功能:
import 'dart:math';
void main() {
print(getRandomLetter('Hello World'));
}
final _rnd = Random();
String getRandomLetter(String input) => input[_rnd.nextInt(input.length)];
关于dart - 是否有任何功能可以从DART中的给定字符串中选择随机字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58427831/