character function

String character({
  1. bool? alpha,
  2. String? pool,
  3. bool? numeric,
  4. Casing? casing,
  5. bool? symbols,
})

Return a random character. Usage character() character({ pool: 'abcde' }) chance.character({ alpha: true }) chance.character({ numeric: true }) chance.character({ casing: 'lower' }) chance.character({ symbols: true })

Implementation

// => 'c'
/// Usage
/// ```character()```
/// ```character({ pool: 'abcde' })```
/// ```chance.character({ alpha: true })```
/// ```chance.character({ numeric: true })```
/// ```chance.character({ casing: 'lower' })```
/// ```chance.character({ symbols: true })```
///
String character({
  bool? alpha,

  /// Optionally specify a pool and the character will be generated with
  /// characters only from that pool.
  /// By default it will return a string with random character from the
  /// following pool.
  /// [_chars]
  String? pool,

  /// Optionally specify numeric for a numeric character.
  bool? numeric,

  /// Default includes both upper and lower case. It's possible to specify
  /// one or the other.
  Casing? casing,

  /// Optionally return only symbols
  bool? symbols,
}) {
  assert(alpha == true && numeric == true);
  assert(casing != null && symbols == true);
  if (alpha == null &&
      pool == null &&
      numeric == null &&
      casing == null &&
      symbols == null) {
    return _getRandomString();
  } else if (alpha == true) {
    return _getRandomString(_upperCaseChars);
  } else if (pool != null) {
    return _getRandomString(pool);
  } else if (casing != null) {
    if (casing == Casing.lower) {
      return _getRandomString(_lowerCaseChars);
    }

    return _getRandomString(_upperCaseChars);
  } else if (symbols != null) {
    return _getRandomString(_symbols);
  }
  return _getRandomString();
}