2021年1月25日星期一

how to random generate name in Dart?

I need to generate random name for people's name, school, class, etc. I found this script on stackoverflow,

 import 'dart:math';    void main() {    print(getRandomString(5));  // 5GKjb    print(getRandomString(10)); // LZrJOTBNGA    print(getRandomString(15)); // PqokAO1BQBHyJVK  }    const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';  Random _rnd = Random();    String getRandomString(int length) => String.fromCharCodes(Iterable.generate(      length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));  

i need to make it pick a word, but not each char, how do i do that?

i am learning dart, hope you guys can help me. Thank You!

https://stackoverflow.com/questions/65894896/how-to-random-generate-name-in-dart January 26, 2021 at 09:53AM

没有评论:

发表评论