getRandom property
dynamic
get
getRandom
Retrieves a random element from the current Iterable.
The getter creates a Random generator to generate a random index within the range
of the Iterable's length. It uses the nextInt() method of the generator to obtain
a random integer index. It then retrieves the element at the generated index from
the Iterable by converting it to a List using toList().
Returns a random element from the Iterable.
Example:
List<int> numbers = [1, 2, 3, 4, 5];
int randomElement = numbers.getRandom;
print(randomElement); // Output: Randomly selected number from the list
Implementation
dynamic get getRandom {
Random generator = Random();
final index = generator.nextInt(this.length);
return this.toList()[index];
}