[][src]Function randge::randge_linear

pub fn randge_linear<T: PrimInt + AsPrimitive<usize>>(
    range: Range<T>,
    n: T,
    rand: impl FnRand<T>
) -> RandgeIter<T, impl FnRand<T>, RangesLinear<T>>

Notable traits for RandgeIter<T, F, R>

impl<T, F: FnRand<T>, R: RandgeTake<T>> Iterator for RandgeIter<T, F, R> where
    T: PrimInt
type Item = T;

Generate random numbers that are not repeated in the range

  • Based on linear algorithm, the worst time complexity is O(n) and the best O(1)
  • Minimal memory usage
  • Slowest

Example

use rand::thread_rng;
 
let v = randge_linear(-15..15, 5, thread_rng());
let v: Vec<_> = v.collect();
// output: like [13, -3, -14, 5, 3]