How do I generate random numbers in Dart?

前端 未结 14 1280
一个人的身影
一个人的身影 2021-01-31 06:49

How do I generate random numbers using Dart?

14条回答
  •  梦谈多话
    2021-01-31 07:26

    For me the easiest way is to do:

    import 'dart:math';
    Random rnd = new Random();
    r = min + rnd.nextInt(max - min);
    //where min and max should be specified.
    

    Thanks to @adam-singer explanation in here.

提交回复
热议问题