FakeRandom class

A fake Random implementation that always produces a given sequence of values. It should only be used in tests.

Why prefer a FakeRandom over a seeded Random?

A FakeRandom avoids depending on implementation details. A seeded Random is implicitly dependent on the underlying PRNG algorithm. The generated values may change if the algorithm changes. Furthermore, reverse-engineering a seed is cumbersome.

Implemented types
Available extensions
Annotations
  • @visibleForTesting

Constructors

FakeRandom({Iterable<int> ints = const [], Iterable<double> doubles = const [], Iterable<bool> bools = const []})
Creates a FakeRandom with the Iterables used by the various function to produce values.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

doubles({int? length, double min = 0.0, double max = 1.0}) Stream<double>

Available on Random, provided by the Randoms extension

Returns a Stream of length that produces random doubles in the range, [min] <= value < [max].
ints({int? length, int min = 0, required int max}) Stream<int>

Available on Random, provided by the Randoms extension

Returns a Stream of length that produces random integers in the range, [min] <= value < [max].
nextBool() bool
Returns the next boolean in the iterable.
override
nextBoundedDouble(double min, double max) double

Available on Random, provided by the Randoms extension

Generates a random double in the range, [min] <= value < [max].
nextBoundedInt(int min, int max) int

Available on Random, provided by the Randoms extension

Generates a random integer uniformly distributed in the range, [min] <= value < [max].
nextDouble() double
Returns the next double in the iterable.
override
nextInt(int max) int
Returns the next integer in the iterable.
override
nextWeightedBool(double probability) bool

Available on Random, provided by the Randoms extension

Returns a weighted boolean value based on probability.
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