pub fn graphic_weighted_random_chars(
    seed: Seed,
    p_numerator: u64,
    p_denominator: u64
) -> WeightedGraphicRandomCharRange
Expand description

Generates random chars, weighting graphic and non-graphic chars 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 chars is selected with probability $p$, and the set of non-graphic chars with probability $1-p$. Then, a char is selected uniformly from the appropriate set. There are 142,523 graphic chars 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{8d835}𲆽ՠ𦧹\u{37de9}\u{d71d4}𪂋"
)