How do I generate random numbers in Dart?

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

How do I generate random numbers using Dart?

14条回答
  •  [愿得一人]
    2021-01-31 07:30

    Use Random class from dart:math:

    import 'dart:math';
    
    main() {
      var rng = new Random();
      for (var i = 0; i < 10; i++) {
        print(rng.nextInt(100));
      }
    }
    

    This code was tested with the Dart VM and dart2js, as of the time of this writing.

提交回复
热议问题