use crate limbs_slice_mod_power_of_2_in_place;
use crate limbs_slice_set_bit;
use crate Natural;
use Itertools;
use ;
use PrimitiveInt;
use ;
use ExactFrom;
use iterator_to_bit_chunks;
use ;
use ;
use ;
use ;
use Seed;
use RoundingMode;
/// Generates a random [`Natural`] with a given maximum bit length.
///
/// The [`Natural`] is chosen uniformly from $[0, 2^b)$; [`Natural`]s with bit lengths smaller than
/// the maximum may also be generated.
///
/// $$
/// P(n) = \\begin{cases}
/// \frac{1}{2^b} & \text{if} \\quad 0 \\leq n < 2^b, \\\\
/// 0 & \\text{otherwise}.
/// \\end{cases}
/// $$
///
/// # Expected complexity
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and `n` is `bits`.
///
/// # Examples
/// ```
/// use malachite_base::num::random::random_primitive_ints;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::get_random_natural_with_up_to_bits;
///
/// assert_eq!(
/// get_random_natural_with_up_to_bits(&mut random_primitive_ints(EXAMPLE_SEED), 100)
/// .to_string(),
/// "976558340558744279591984426865"
/// );
/// ```
/// Generates a random [`Natural`] with a given bit length.
///
/// The [`Natural`] is 0 if $b$ is 0, or else chosen uniformly from $[2^{b-1}, 2^b)$.
///
/// $$
/// P(n) = \\begin{cases}
/// 1 & \text{if} \\quad b = n = 0, \\\\
/// \frac{1}{2^{b-1}} & \text{if} \\quad b \neq 0 \\ \text{and} \\ 2^{b-1} \leq n < 2^b, \\\\
/// 0 & \\text{otherwise}.
/// \\end{cases}
/// $$
///
/// # Expected complexity
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and `n` is `bits`.
///
/// # Examples
/// ```
/// use malachite_base::num::random::random_primitive_ints;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::get_random_natural_with_bits;
///
/// assert_eq!(
/// get_random_natural_with_bits(&mut random_primitive_ints(EXAMPLE_SEED), 100).to_string(),
/// "976558340558744279591984426865"
/// );
/// ```
/// Generates a striped random [`Natural`] with a given maximum bit length.
///
/// [`Natural`]s with bit lengths smaller than the maximum may also be generated.
///
/// See [`StripedBitSource`](StripedBitSource) for information about generating striped random
/// numbers.
///
/// # Expected complexity
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and `n` is `bits`.
///
/// # Examples
/// ```
/// use malachite_base::num::random::striped::StripedBitSource;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::get_striped_random_natural_with_up_to_bits;
///
/// let mut bit_source = StripedBitSource::new(EXAMPLE_SEED, 10, 1);
/// // 0x3fffff80000ffc007ffe03ff8
/// assert_eq!(
/// get_striped_random_natural_with_up_to_bits(&mut bit_source, 100).to_string(),
/// "316912612278197474676665499640"
/// );
/// ```
/// Generates a striped random [`Natural`] with a given bit length.
///
/// See [`StripedBitSource`](StripedBitSource) for information about generating striped random
/// numbers.
///
/// # Expected complexity
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and `n` is `bits`.
///
/// # Examples
/// ```
/// use malachite_base::num::random::striped::StripedBitSource;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::get_striped_random_natural_with_bits;
///
/// let mut bit_source = StripedBitSource::new(EXAMPLE_SEED, 10, 1);
/// // 0xbfffff80000ffc007ffe03ff8
/// assert_eq!(
/// get_striped_random_natural_with_bits(&mut bit_source, 100).to_string(),
/// "950737912392312175425017102328"
/// );
/// ```
/// Generates random [`Natural`]s, given an iterator of random bit lengths.
/// Generates random [`Natural`]s with a specified mean bit length.
///
/// The actual bit length is chosen from a geometric distribution with mean $m$, where $m$ is
/// `mean_bits_numerator / mean_bits_denominator`; $m$ must be greater than 0. Then a [`Natural`]
/// is chosen uniformly among all [`Natural`]s with that bit length. The resulting distribution
/// resembles a Pareto distribution. It has no mean or higher-order statistics (unless $m < 1$,
/// which is not typical).
///
/// $$
/// P(n) = \\begin{cases}
/// \\frac{1}{m + 1} & \text{if} \\quad n = 0, \\\\
/// \\frac{2}{m+1} \\left ( \\frac{m}{2(m+1)} \\right ) ^ {\\lfloor \\log_2 n \\rfloor + 1} &
/// \text{if} \\quad \\text{otherwise}.
/// \\end{cases}
/// $$
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $E(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ is
/// `mean_bits_numerator + mean_bits_denominator`.
///
/// # Panics
/// Panics if `mean_bits_numerator` or `mean_bits_denominator` are zero, or, if after being reduced
/// to lowest terms, their sum is greater than or equal to $2^{64}$.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::random_naturals;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(random_naturals(EXAMPLE_SEED, 32, 1), 10),
/// "[20431208470830262, 2777240, 114, 12184833305054, 1121025855008623490210, \
/// 13478874522577592, 115311695, 7, 18, 54522366353, ...]"
/// )
/// ```
/// Generates random positive [`Natural`]s with a specified mean bit length.
///
/// The actual bit length is chosen from a geometric distribution with mean $m$, where $m$ is
/// `mean_bits_numerator / mean_bits_denominator`; $m$ must be greater than 1. Then a [`Natural`]
/// is chosen uniformly among all [`Natural`]s with that bit length. The resulting distribution
/// resembles a Pareto distribution. It has no mean or higher-order statistics (unless $m < 2$,
/// which is not typical).
///
/// $$
/// P(n) = \\begin{cases}
/// 0 & \text{if} \\quad n = 0, \\\\
/// \frac{1}{m} \left ( \frac{m-1}{2m} \right ) ^ {\lfloor \log_2 n \rfloor} &
/// \\text{otherwise}.
/// \\end{cases}
/// $$
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ is
/// `mean_bits_numerator + mean_bits_denominator`.
///
/// # Panics
/// Panics if `mean_bits_numerator` or `mean_bits_denominator` are zero or if
/// `mean_bits_numerator <= mean_bits_denominator`.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::random_positive_naturals;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(random_positive_naturals(EXAMPLE_SEED, 32, 1), 10),
/// "[22, 4, 178, 55845661150, 93254818, 7577967529619388, 8, 11316951483471, 11, \
/// 1005760138411689342464923704482, ...]"
/// )
/// ```
/// Generates striped random [`Natural`]s, given an iterator of random bit lengths.
/// Generates striped random [`Natural`]s with a specified mean bit length.
///
/// The actual bit length is chosen from a geometric distribution with mean $m$, where $m$ is
/// `mean_bits_numerator / mean_bits_denominator`; $m$ must be greater than 0. A striped bit
/// sequence with the given stripe parameter is generated and truncated at the bit length. The
/// highest bit is forced to be 1, and the [`Natural`] is generated from the sequence.
///
/// See [`StripedBitSource`](StripedBitSource) for information about generating striped random
/// numbers.
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ is
/// `mean_bits_numerator + mean_bits_denominator`.
///
/// # Panics
/// Panics if `mean_stripe_denominator` is zero, if
/// `mean_stripe_numerator < mean_stripe_denominator`, if `mean_bits_numerator` or
/// `mean_bits_denominator` are zero, or, if after being reduced to lowest terms, their sum is
/// greater than or equal to $2^{64}$.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::striped_random_naturals;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(striped_random_naturals(EXAMPLE_SEED, 16, 1, 32, 1), 10),
/// "[18014656207519744, 2228160, 64, 17592184995840, 1179440951012584587264, \
/// 9007749010526207, 67108864, 5, 24, 34359738879, ...]"
/// )
/// ```
/// Generates striped random positive [`Natural`]s with a specified mean bit length.
///
/// The actual bit length is chosen from a geometric distribution with mean $m$, where $m$ is
/// `mean_bits_numerator / mean_bits_denominator`; $m$ must be greater than 1. A striped bit
/// sequence with the given stripe parameter is generated and truncated at the bit length. The
/// highest bit is forced to be 1, and the [`Natural`] is generated from the sequence.
///
/// See [`StripedBitSource`](StripedBitSource) for information about generating striped random
/// numbers.
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ is
/// `mean_bits_numerator + mean_bits_denominator`.
///
/// # Panics
/// Panics if `mean_stripe_denominator` is zero, if
/// `mean_stripe_numerator < mean_stripe_denominator`, if `mean_bits_numerator` or
/// `mean_bits_denominator` are zero, or if `mean_bits_numerator <= mean_bits_denominator`.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::striped_random_positive_naturals;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(striped_random_positive_naturals(EXAMPLE_SEED, 16, 1, 32, 1), 10),
/// "[16, 4, 128, 34391195648, 75493376, 9007199120523391, 8, 8796094070783, 8, \
/// 950737950171027935941967741439, ...]"
/// )
/// ```
/// Uniformly generates random [`Natural`]s less than a positive limit.
/// Uniformly generates random [`Natural`]s less than a positive `limit`.
///
/// $$
/// P(x) = \\begin{cases}
/// \frac{1}{\\ell} & \text{if} \\quad x < \\ell, \\\\
/// 0 & \\text{otherwise}.
/// \\end{cases}
/// $$
/// where $\ell$ is `limit`.
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ is `limit.significant_bits()`.
///
/// # Panics
/// Panics if `limit` is 0.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::random_naturals_less_than;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(random_naturals_less_than(EXAMPLE_SEED, Natural::from(10u32)), 10),
/// "[1, 7, 5, 7, 9, 2, 8, 2, 4, 6, ...]"
/// )
/// ```
/// Uniformly generates random [`Natural`]s in an interval.
/// Uniformly generates random [`Natural`]s in the half-open interval $[a, b)$.
///
/// $a$ must be less than $b$.
///
/// $$
/// P(x) = \\begin{cases}
/// \frac{1}{b-a} & \text{if} \\quad a \leq x < b, \\\\
/// 0 & \\text{otherwise}.
/// \\end{cases}
/// $$
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ is `b.significant_bits()`.
///
/// # Panics
/// Panics if $a \geq b$.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::uniform_random_natural_range;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(
/// uniform_random_natural_range(
/// EXAMPLE_SEED,
/// Natural::from(10u32),
/// Natural::from(100u32)
/// ),
/// 10
/// ),
/// "[97, 17, 94, 37, 56, 32, 96, 11, 17, 39, ...]"
/// )
/// ```
/// Uniformly generates random [`Natural`]s in the closed interval $[a, b]$.
///
/// $a$ must be less than or equal to $b$.
///
/// $$
/// P(x) = \\begin{cases}
/// \frac{1}{b-a+1} & \text{if} \\quad a \leq x \leq b, \\\\
/// 0 & \\text{otherwise}.
/// \\end{cases}
/// $$
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ is `b.significant_bits()`.
///
/// # Panics
/// Panics if $a > b$.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::uniform_random_natural_inclusive_range;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(
/// uniform_random_natural_inclusive_range(
/// EXAMPLE_SEED,
/// Natural::from(10u32),
/// Natural::from(99u32)
/// ),
/// 10
/// ),
/// "[97, 17, 94, 37, 56, 32, 96, 11, 17, 39, ...]"
/// )
/// ```
/// Generates random [`Natural`]s greater than or equal to a lower bound.
/// Generates random [`Natural`]s greater than or equal to a lower bound $a$.
///
/// The mean bit length $m$ of the [`Natural`]s is specified; it must be greater than the bit
/// length of $a$. $m$ is equal to `mean_bits_numerator / mean_bits_denominator`.
///
/// The actual bit length is chosen from a geometric distribution with lower bound $a$ and mean $m$.
/// Then a [`Natural`] is chosen uniformly among all [`Natural`]s with that bit length that are
/// greater than or equal to $a$. The resulting distribution has no mean or higher-order statistics
/// (unless $a < m < a + 1$, which is not typical).
///
/// $$
/// P(n) = \\begin{cases}
/// 0 & \text{if} \\quad n < a, \\\\
/// \frac{1}{m+1} & \text{if} \\quad a = n = 0, \\\\
/// \frac{m}{(m+1)^2}\left ( \frac{m}{2(m+1)} \right )^\nu &
/// \text{if} \\quad 0 = a < n, \\\\
/// \frac{1}{(2^{\nu + 1}-a)(m-\alpha)} &
/// \text{if} \\quad 0 < a \\ \text{and} \\ \alpha = \nu, \\\\
/// \frac{\left ( 1 - \frac{1}{\alpha-m}\right )^{\nu-\alpha}}{2^\nu(m-\alpha)} &
/// \text{if} \\quad 0 < a \\ \text{and} \\ \alpha < \nu, \\\\
/// \\end{cases}
/// $$
/// where $\alpha = \lfloor \log_2 a \rfloor$ and $\nu = \lfloor \log_2 n \rfloor$.
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(m) = O(m)$
///
/// where $T$ is time, $M$ is additional memory, $n$ is
/// `mean_bits_numerator + mean_bits_denominator`, and $m$ is
/// `mean_bits_numerator / mean_bits_denominator`.
///
/// # Panics
/// Panics if `mean_bits_numerator` or `mean_bits_denominator` are zero, if their ratio is less than
/// or equal to $a$, or if they are too large and manipulating them leads to arithmetic overflow.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::random_natural_range_to_infinity;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(
/// random_natural_range_to_infinity(EXAMPLE_SEED, Natural::from(1000u32), 20, 1),
/// 10
/// ),
/// "[3254, 4248, 163506, 1189717027294, 5282, 12220, 60088, 1016911, 5772451, 5473099750562, \
/// ...]"
/// )
/// ```
/// Generates random [`Natural`]s in an interval.
/// Generates random [`Natural`]s in the half-open interval $[a, b)$.
///
/// In general, the [`Natural`]s are not generated uniformly; for that, use
/// [`uniform_random_natural_range`]. Instead, [`Natural`]s with smaller bit lengths are generated
/// more frequently.
///
/// The distribution of generated values is parametrized by a number $m$, given by
/// `mean_bits_numerator / mean_bits_denominator`. It is not actually the mean bit length, though
/// it approaches the mean bit length as $\log (b/a)$ approaches infinity. $m$ must be greater than
/// $a$, but it may be arbitrarily large. The smaller it is, the more quickly the probabilities
/// decrease as bit length increases. The larger it is, the more closely the distribution approaches
/// a uniform distribution over the bit lengths.
///
/// Once a bit length is selected, the [`Natural`] is chosen uniformly from all [`Natural`]s with
/// that bit length that are in $[a, b)$.
///
/// To obtain the probability mass function, adjust $b$ and see [`random_natural_inclusive_range`].
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(m) = O(m)$
///
/// where $T$ is time, $M$ is additional memory, $n$ is
/// `mean_bits_numerator + mean_bits_denominator`, and $m$ is `b.significant_bits()`.
///
/// # Panics
/// Panics if $a \geq b$, if `mean_bits_numerator` or `mean_bits_denominator` are zero, if their
/// ratio is less than or equal to $a$, or if they are too large and manipulating them leads to
/// arithmetic overflow.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::random_natural_range;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(
/// random_natural_range(
/// EXAMPLE_SEED,
/// Natural::from(1000u32),
/// Natural::from(1000000000u32),
/// 20,
/// 1
/// ),
/// 10
/// ),
/// "[3254, 4248, 163506, 600542, 5282, 12220, 60088, 1016911, 5772451, 2792610, ...]"
/// )
/// ```
/// Generates random [`Natural`]s in the closed interval $[a, b]$.
///
/// In general, the [`Natural`]s are not generated uniformly; for that, use
/// [`uniform_random_natural_inclusive_range`]. Instead, [`Natural`]s with smaller bit lengths are
/// generated more frequently.
///
/// The distribution of generated values is parametrized by a number $m$, given by
/// `mean_bits_numerator / mean_bits_denominator`. It is not actually the mean bit length, though
/// it approaches the mean bit length as $\log (b/a)$ approaches infinity. $m$ must be greater than
/// $a$, but it may be arbitrarily large. The smaller it is, the more quickly the probabilities
/// decrease as bit length increases. The larger it is, the more closely the distribution approaches
/// a uniform distribution over the bit lengths.
///
/// Once a bit length is selected, the [`Natural`] is chosen uniformly from all [`Natural`]s with
/// that bit length that are in $[a, b]$.
///
/// $$
/// P(n) = \\begin{cases}
/// 0 & \text{if} \\quad n < a \\ \text{or} \\ n > b, \\\\
/// 1 & \text{if} \\quad a = n = b = 0, \\\\
/// \frac{1}{b-a} & \text{if} \\quad 0 < a \\ \text{and} \\ \alpha = \beta, \\\\
/// \left \[ (m+1)\left ( 1-\left (\frac{m}{m+1}\right )^{\beta+2} \right ) \right \]^{-1} &
/// \text{if} \\quad 0 = a = n < b \\\\
/// (2^{\alpha+1}-n)\left \[ (m-\alpha)\left ( 1+\frac{1}{\alpha-m}\right )^{\alpha-\nu}-
/// (m-\alpha-1)\left ( 1+\frac{1}{\alpha-m}\right )^{\beta-\nu}\right \]^{-1} &
/// \text{if} \\quad 0 < a \\ \text{and} \\ \alpha = \nu < \beta, \\\\
/// \frac{m^{\nu+1}(m+1)^{\beta-\nu}}{((m+1)^{\beta+2}-m^{\beta+2})(2^\beta-n+1)} &
/// \text{if} \\quad 0 = a < n \\ \text{and} \\ \nu = \beta, \\\\
/// (n-2^\beta+1)\left \[ (m-\alpha)\left ( 1+\frac{1}{\alpha-m}\right )^{\alpha-\nu}-
/// (m-\alpha-1)\left ( 1+\frac{1}{\alpha-m}\right )^{\beta-\nu}\right \]^{-1} &
/// \text{if} \\quad 0 < a \\ \text{and} \\ \alpha < \nu = \beta, \\\\
/// \frac{m(m+1)^\beta \left ( \frac{m}{2(m+1)}\right )^\nu}{(m+1)^{\beta+2}-m^{\beta+2}} &
/// \text{if} \\quad 0 = a < n \\ \text{and} \\ \nu < \beta, \\\\
/// 2^{-\nu}\left \[ (m-\alpha)\left ( 1+\frac{1}{\alpha-m}\right )^{\alpha-\nu}-(m-\alpha-1)
/// \left ( 1+\frac{1}{\alpha-m}\right )^{\beta-\nu}\right \]^{-1} &
/// \text{if} \\quad 0 < a \\ \text{and} \\ \alpha < \nu < \beta,
/// \\end{cases}
/// $$
/// where $\alpha = \lfloor \log_2 a \rfloor$, $\beta = \lfloor \log_2 b \rfloor$, and
/// $\nu = \lfloor \log_2 n \rfloor$.
///
/// The output length is infinite.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(m) = O(m)$
///
/// where $T$ is time, $M$ is additional memory, $n$ is
/// `mean_bits_numerator + mean_bits_denominator`, and $m$ is `b.significant_bits()`.
///
/// # Panics
/// Panics if $a > b$, if `mean_bits_numerator` or `mean_bits_denominator` are zero, if their ratio
/// is less than or equal to $a$, or if they are too large and manipulating them leads to
/// arithmetic overflow.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::random_natural_inclusive_range;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(
/// random_natural_inclusive_range(
/// EXAMPLE_SEED,
/// Natural::from(1000u32),
/// Natural::from(1000000000u32),
/// 20,
/// 1
/// ),
/// 10
/// ),
/// "[3254, 4248, 163506, 600542, 5282, 12220, 60088, 1016911, 5772451, 2792610, ...]"
/// )
/// ```
/// Generates random striped [`Natural`]s from a range.
/// Generates random striped [`Natural`]s in the range $[a, b)$.
///
/// The [`Natural`] are generated using a striped bit sequence with mean run length $m$, which is
/// `mean_stripe_numerator / mean_stripe_denominator`.
///
/// Because the [`Natural`] are constrained to be within a certain range, the actual mean run
/// length will usually not be $m$. Nonetheless, setting a higher $m$ will result in a higher mean
/// run length.
///
/// See [`StripedBitSource`](StripedBitSource) for information about generating striped random
/// numbers.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ is `b.significant_bits()`.
///
/// # Panics
/// Panics if `mean_stripe_denominator` is zero, if
/// `mean_stripe_numerator <= mean_stripe_denominator`, or if $a > b$.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::num::basic::traits::One;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_base::strings::ToBinaryString;
/// use malachite_nz::natural::Natural;
/// use malachite_nz::natural::random::striped_random_natural_range;
///
/// assert_eq!(
/// prefix_to_string(
/// striped_random_natural_range(EXAMPLE_SEED, Natural::ONE, Natural::from(7u32), 4, 1)
/// .map(|x| x.to_binary_string()),
/// 10
/// ),
/// "[1, 1, 1, 110, 1, 110, 10, 11, 11, 100, ...]"
/// );
/// ```
/// Generates random striped [`Natural`]s in the range $[a, b]$.
///
/// The [`Natural`]s are generated using a striped bit sequence with mean run length
/// $m$ = `mean_stripe_numerator / mean_stripe_denominator`.
///
/// Because the [`Natural`] are constrained to be within a certain range, the actual mean run
/// length will usually not be $m$. Nonetheless, setting a higher $m$ will result in a higher mean
/// run length.
///
/// See [`StripedBitSource`](StripedBitSource) for information about generating striped random
/// numbers.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(n) = O(n)$
///
/// where $T$ is time, $M$ is additional memory, and $n$ is `b.significant_bits()`.
///
/// # Panics
/// Panics if `mean_stripe_denominator` is zero, if
/// `mean_stripe_numerator <= mean_stripe_denominator`, or if $a > b$.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::num::basic::traits::One;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_base::strings::ToBinaryString;
/// use malachite_nz::natural::Natural;
/// use malachite_nz::natural::random::striped_random_natural_inclusive_range;
///
/// assert_eq!(
/// prefix_to_string(
/// striped_random_natural_inclusive_range(
/// EXAMPLE_SEED,
/// Natural::ONE,
/// Natural::from(6u32),
/// 4,
/// 1
/// ).map(|x| x.to_binary_string()),
/// 10
/// ),
/// "[1, 1, 1, 110, 1, 110, 10, 11, 11, 100, ...]"
/// );
/// ```
/// Generates striped random [`Natural`]s greater than or equal to a lower bound.
/// Generates striped random [`Natural`]s greater than or equal to a lower bound $a$.
///
/// The mean bit length $m$ of the [`Natural`]s is specified; it must be greater than the bit
/// length of $a$. $m$ is equal to `mean_bits_numerator / mean_bits_denominator`.
///
/// The actual bit length is chosen from a geometric distribution with lower bound $a$ and mean $m$.
/// The resulting distribution has no mean or higher-order statistics (unless $a < m < a + 1$,
/// which is not typical).
///
/// The [`Natural`]s are generated using a striped bit sequence with mean run length
/// $m$ = `mean_stripe_numerator / mean_stripe_denominator`.
///
/// Because the [`Natural`] are constrained to be within a certain range, the actual mean run
/// length will usually not be $m$. Nonetheless, setting a higher $m$ will result in a higher mean
/// run length.
///
/// The output length is infinite.
///
/// See [`StripedBitSource`](StripedBitSource) for information about generating striped random
/// numbers.
///
/// # Expected complexity per iteration
/// $T(n) = O(n)$
///
/// $M(m) = O(m)$
///
/// where $T$ is time, $M$ is additional memory, $n$ is
/// `mean_bits_numerator + mean_bits_denominator`, and $m$ is
/// `mean_bits_numerator / mean_bits_denominator`.
///
/// # Panics
/// Panics if `mean_stripe_denominator` is zero, if
/// `mean_stripe_numerator < mean_stripe_denominator`, if `mean_bits_numerator` or
/// `mean_bits_denominator` are zero, if their ratio is less than or equal to $a$, or if they are
/// too large and manipulating them leads to arithmetic overflow.
///
/// # Examples
/// ```
/// use malachite_base::iterators::prefix_to_string;
/// use malachite_base::random::EXAMPLE_SEED;
/// use malachite_nz::natural::random::striped_random_natural_range_to_infinity;
/// use malachite_nz::natural::Natural;
///
/// assert_eq!(
/// prefix_to_string(
/// striped_random_natural_range_to_infinity(
/// EXAMPLE_SEED,
/// Natural::from(1000u32),
/// 20,
/// 1,
/// 14,
/// 1
/// ),
/// 10
/// ),
/// "[8192, 14336, 16376, 1024, 1024, 1023, 2047, 245760, 8195, 131070, ...]"
/// )
/// ```