A generator of random bool, int, or double values.
The default implementation supplies a stream of pseudo-random bits that are not suitable for cryptographic purposes.
Use the Random.secure constructor for cryptographic purposes.
To create a non-negative random integer uniformly distributed in the range from 0, inclusive, to max, exclusive, use nextInt(int max).
var intValue = Random().nextInt(10); // Value is >= 0 and < 10. intValue = Random().nextInt(100) + 50; // Value is >= 50 and < 150.
To create a non-negative random floating point value uniformly distributed in the range from 0.0, inclusive, to 1.0, exclusive, use nextDouble.
var doubleValue = Random().nextDouble(); // Value is >= 0.0 and < 1.0. doubleValue = Random().nextDouble() * 256; // Value is >= 0.0 and < 256.0.
To create a random Boolean value, use nextBool.
var boolValue = Random().nextBool(); // true or false, with equal chance.
max, exclusive.
© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.18.5/dart-math/Random-class.html