Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method to produce randomly generated numbers in Dart is the Random() class. This class provides different methods to generate random numbers such as nextInt(), nextDouble(), and nextBool().

Example:

import 'dart:math';

void main() {
  // create a random number generator
  Random rng = Random();

  // generate a random integer between 0 and 9
  int randomInt = rng.nextInt(10);
  print(randomInt);

  // generate a random double between 0.0 and 1.0
  double randomDouble = rng.nextDouble();
  print(randomDouble);

  // generate a random boolean value
  bool randomBool = rng.nextBool();
  print(randomBool);
}