Functions for generating restricted permutations of data