Function malachite_base::num::random::random_signed_bit_chunks
source · pub fn random_signed_bit_chunks<T: PrimitiveSigned>(
seed: Seed,
chunk_size: u64
) -> RandomSignedBitChunks<T> ⓘ
Expand description
Uniformly generates signed integers containing some maximum number of bits.
The generated values will all be non-negative unless chunk_size
is equal to the width of the
type.
$$
P(x) = \begin{cases}
2^{-c} & \text{if} \quad c = W \ \text{or}
\ (c < W \ \text{and} \ 0 \leq x < 2^c), \\
0 & \text{otherwise,}
\end{cases}
$$
where $c$ is chunk_size
and $W$ is the width of the type.
The output length is infinite.
Complexity per iteration
Constant time and additional memory.
Panics
Panics if chunk_size
is zero or greater than the width of the type.
Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::random::random_signed_bit_chunks;
use malachite_base::random::EXAMPLE_SEED;
assert_eq!(
prefix_to_string(random_signed_bit_chunks::<i8>(EXAMPLE_SEED, 3), 10),
"[1, 6, 5, 7, 6, 3, 1, 2, 4, 5, ...]"
)