getString static method
Generates a random string of specified length from the given character set.
Parameters:
data
: The character set to use for generating the string.max
: The length of the generated string.seed
: Seed for the random number generator. Default is null.
Example:
String randomString = RandomProvider.getString(data: 'abc123', max: 8, seed: 42);
// Result: Random string of length 8 using characters 'a', 'b', 'c', '1', '2', '3'.
Implementation
static String getString({
required String data,
required int max,
int? seed,
}) {
final Random random = Random(seed);
var characters = data.characters;
var value = '';
for (int i = 0; i < max; ++i) {
final a = characters.elementAt(random.nextInt(characters.length));
value = "$value$a";
}
return value;
}