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.
Constructors
- Random([int? seed])
-
Creates a random number generator.
factory
- Random.secure()
-
Creates a cryptographically secure random number generator.
factory
Properties
- hashCode → int
-
The hash code for this object.
read-onlyinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
Methods
-
nextBool(
) → bool - Generates a random boolean value.
-
nextDouble(
) → double - Generates a non-negative random floating point value uniformly distributed in the range from 0.0, inclusive, to 1.0, exclusive.
-
nextInt(
int max) → int -
Generates a non-negative random integer uniformly distributed in the range
from 0, inclusive, to
max
, exclusive. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited