getValue<T> static method
Retrieves a random value from the provided list.
Parameters:
data
: The list of values.max
: The maximum index to use for selecting a value.min
: The minimum index to use for selecting a value. Default is 0.seed
: Seed for the random number generator. Default is null.
Example:
List<String> options = ['A', 'B', 'C', 'D'];
String? randomValue = RandomProvider.getValue(data: options, max: 4, min: 1, seed: 42);
// Result: Random value from the list ['B', 'C', 'D'].
Implementation
static T? getValue<T>({
required List<T> data,
required int max,
int min = 0,
int? seed,
}) {
if (data.isNotEmpty) {
return data[getInt(max: data.length, min: min, seed: seed)];
} else {
return null;
}
}