PERMUTE-BY-SORTING with similar priorities
The easiest way is to generate a random permutation in $P$. Here is pseudocode:


Initialize $P$ with $P[i] = i$ for $i = 1,\ldots,n$.
Repeat for $i = 1,\ldots,n-1$:

Let $j$ be a random number in the range $i,\ldots,n$.
Swap $P[i]$ and $P[j]$.