randomAlpha function

String randomAlpha(
  1. int length, {
  2. AbstractRandomProvider provider = const DefaultRandomProvider(),
})

Generates a random string of length with only alpha characters.

Implementation

String randomAlpha(int length, {AbstractRandomProvider provider = const DefaultRandomProvider()}) {
  var lowerAlphaWeight = provider.nextDouble();
  var upperAlphaWeight = provider.nextDouble();
  final sumWeight = lowerAlphaWeight + upperAlphaWeight;
  lowerAlphaWeight /= sumWeight;
  upperAlphaWeight /= sumWeight;
  final lowerAlphaLength = randomBetween(0, length, provider: provider);
  final upperAlphaLength = length - lowerAlphaLength;
  final lowerAlpha = randomString(lowerAlphaLength, from: lowerAlphaStart, to: lowerAlphaEnd, provider: provider);
  final upperAlpha = randomString(upperAlphaLength, from: upperAlphaStart, to: upperAlphaEnd, provider: provider);
  return randomMerge(lowerAlpha, upperAlpha);
}