Function malachite_nz::natural::random::get_random_natural_with_up_to_bits
source · pub fn get_random_natural_with_up_to_bits(
xs: &mut RandomPrimitiveInts<u64>,
bits: u64
) -> Natural
Expand description
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"
);