How do get a random element from a List in Dart?

前端 未结 4 1016
陌清茗
陌清茗 2021-02-05 03:16

How can I retrieve a random element from a collection in Dart?

var list = [\'a\',\'b\',\'c\',\'d\',\'e\'];
4条回答
  •  借酒劲吻你
    2021-02-05 04:01

    import "dart:math";
    
    var list = ['a','b','c','d','e'];
    
    list[Random().nextInt(list.length)]
    

提交回复
热议问题