kpermute

permuted

fun <T> List<T>.permuted(perm: IntPermutation = intPermutation(size)): List<T>(source)

Returns a new list whose elements are permuted by perm. The original list is not modified.

Example:

val perm = intPermutation(5, seed = 42)<br>val shuffled = listOf("a","b","c","d","e").permuted(perm)

range

Returns a view of this permutation that operates on range instead of [0, size). Only valid for finite domains where range.count() == size.

Useful for permuting values within numeric subranges such as dataset shards, sliding windows, or bounded ID segments without manual offset math.

unpermuted

Applies the inverse of perm as a view, restoring the original order.