How do I generate random numbers in Dart?

By Using Random class from math library we can generate rrandom number in flutter

example:

import 'dart:math';

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

 

To generate a list with random numbers 

import 'dart:math';

main() {
  var rng = new Random();
  var l = new List.generate(10, (_) => rng.nextInt(100));
}

This will generate list with 10 random numbers between 0-99 


Flutter Questions

Android Questions

Python Questions

Java Questions