The OpenD Programming Language

shuffle

Partially shuffles the elements of range such that upon returning range[0..n] is a random subset of range and is randomly ordered. range[n..r.length] will contain the elements not in range[0..n]. These will be in an undefined order, but will not be random in the sense that their order after shuffle returns will not be independent of their order before shuffle was called.

Parameters

range Slice!Iterator

random-access range with length whose elements are to be shuffled

n size_t

number of elements of r to shuffle (counting from the beginning); must be less than r.length Complexity: O(n)

Examples

static if (is(typeof({ import mir.ndslice.slice; })))
{
    import mir.ndslice.allocation: slice;
    import mir.ndslice.topology: iota;
    import mir.ndslice.sorting;

    auto a = iota(10).slice;

    shuffle(a, 4);

    sort(a);
    assert(a == iota(10));
}

Meta