---
name: "wnprm"
section: "3"
platform: "linux"
package: "libwn-dev"
version: "6.0-17"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/wnprm"
---

# wnprm(3)

permutation package

## NAME

wn\_random\_permutation, wn\_identity\_permutation, wn\_permute\_permutation, wn\_permute\_array, wn\_invert\_permutation, wn\_is\_valid\_permutation - permutation package

## SYNOPSIS

```
#include <wn/wnprm.h>

wn_random_permutation(int permutation[],int size)

wn_identity_permutation(int permutation[],int size)

wn_permute_permutation(int result[],int perm1[],int perm2[],int size)

wn_permute_array(type result[],int permutation[],type array[],int size)

wn_invert_permutation(int inverse[],int permutation[],int size)

bool wn_is_valid_permutation(int permutation[],int size)
```

## DESCRIPTION

This package produces and operates on permutations.  A permutation is an int array of size *size*.  It contains the ints 0 to *size*-1 in some order.  A permutation defines a reordering of an array of objects of size *size*; the permutation array entry value defines where the reordered object comes from.

**wn\_random\_permutation** produces a random permutation using **wn\_random\_int\_between**.

**wn\_identity\_permutation** produces the identity permutation, that is, \[0 1 2 3 ... *size*-1\].  This permutation produces no reordering.

**wn\_permute\_permutation** applies permutation *perm1* to *perm2*, placing the result in *result*.  Since entries of *result* change during execution, *result* must not overlap with *perm1* or *perm2*.

**wn\_permute\_array** is a macro which applies permutation *permutation* to *array*, placing the result in *result*. The arrays *result* and *array* must be of the same type. Since entries of *result* change during execution, *result* must not overlap with *permutation* or *array*.

**wn\_invert\_permutation** inverts permutation *permutation*, placing the result in *inverse*.  Since entries of *inverse*  change during execution, *inverse* must not  overlap with *permutation*.

**wn\_is\_valid\_permutation** returns **TRUE** if *permutation* is a valid permutation; otherwise it returns **FALSE**.

## EXAMPLES

## RESOURCES

**wn\_random\_permutation** and **wn\_is\_valid\_permutation** run with

WORST and AVERAGE CASE:

time = n\
 stack memory = 1\
 dynamic memory = n

**wn\_identity\_permutation**, **wn\_permute\_permutation**, **wn\_permute\_array**, and **wn\_invert\_permutation** run with

WORST and AVERAGE CASE:

time = n\
 stack memory = 1\
 dynamic memory = 0

In the above, n is *size*, the size of the permutation.

## SEE ALSO

wnrnd

## AUTHOR

Will Naylor
