Function malachite_base::chars::random::graphic_weighted_random_chars
source · [−]pub fn graphic_weighted_random_chars(
seed: Seed,
p_numerator: u64,
p_denominator: u64
) -> WeightedGraphicRandomCharRangeⓘNotable traits for WeightedGraphicRandomCharRangeimpl Iterator for WeightedGraphicRandomCharRange type Item = char;
Expand description
Generates random char
s, weighting graphic and non-graphic char
s separately.
See char_is_graphic
for the definition of a graphic
char
.
Let $n_p$ be p_numerator
and $d_p$ be p_denominator
, and let $p = p_n/p_d$.
The set of graphic char
s is selected with probability $p$, and the set of non-graphic
char
s with probability $1-p$. Then, a char
is selected uniformly from the appropriate
set. There are 142,523 graphic char
s out of 1,112,064, so we have
$$ P(x) = \begin{cases} \frac{p}{142523} & \text{if} \quad x \ \text{is} \ \text{graphic} \\ \frac{1-p}{969541} & \text{otherwise} \end{cases} $$
To recover the uniform distribution, use $p = 142523/1112064$, which is roughly $1/8$.
The output length is infinite.
Expected complexity per iteration
Constant time and additional memory.
Panics
Panics if p_denominator
is zero or p_denominator > p_denominator
.
Examples
use malachite_base::chars::random::graphic_weighted_random_chars;
use malachite_base::random::EXAMPLE_SEED;
assert_eq!(
graphic_weighted_random_chars(EXAMPLE_SEED, 10, 11)
.take(20)
.collect::<String>()
.as_str(),
"𘌮𰠁礣깼ꅐ枃쭧𬡵╲𣕽⢎𰾞瀑\u{8c6d6}ՠ𦫷𪆉\u{36c8a}\u{d6075}𧂻"
)