Function select_char
pub fn select_char(
rnd: &mut impl Rng,
special: &[char],
preferred: &[RangeInclusive<char>],
ranges: &[RangeInclusive<char>],
) -> char
Expand description
Selects a random character the way CharStrategy
does.
If special
is non-empty, there is a 50% chance that a character from this
array is chosen randomly, and will be returned if that character falls
within ranges
.
If preferred
is non-empty, there is a 50% chance that any generation
which gets past the special
step picks a random element from this list,
then a random character from within that range (both endpoints inclusive).
That character will be returned if it falls within ranges
.
In all other cases, an element is picked randomly from ranges
and a
random character within the range (both endpoints inclusive) is chosen and
returned.
Notice that in all cases, ranges
completely defines the set of characters
that can possibly be defined.
It is legal for ranges in all cases to contain non-characters.
Both preferred
and ranges
bias selection towards characters in smaller
ranges. This is deliberate. preferred
is usually tuned to select
particular characters anyway. ranges
is usually derived from some
external property, and the fact that a range is small often means it is
more interesting.