Function malachite_base::num::random::random_signed_inclusive_range
source · [−]pub fn random_signed_inclusive_range<T: PrimitiveSigned>(
seed: Seed,
a: T,
b: T
) -> RandomSignedInclusiveRange<T>ⓘNotable traits for RandomSignedInclusiveRange<T>impl<T: HasRandomSignedRange> Iterator for RandomSignedInclusiveRange<T> type Item = T;
Expand description
Uniformly generates random signed integers 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
Constant time and additional memory.
Panics
Panics if $a > b$.
Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::random::random_signed_inclusive_range;
use malachite_base::random::EXAMPLE_SEED;
assert_eq!(
prefix_to_string(random_signed_inclusive_range::<i8>(EXAMPLE_SEED, -100, 99), 10),
"[13, -31, 8, 68, 61, -13, -68, 10, -17, 88, ...]"
)