Parametrized permutation function I'm looking for a way to construct a function that would work the way depicted in the following picture:

That is, I want it to permute the elements in a given array to put them in some different order depending on a parameter I give it, so that the numbers of my choice from the original set (those I marked with grey background) would all end up as a continuous range at the beginning of the output array (to the left of the thick line), while all other elements (red background) would end up at the remaining positions in that array (to the right of the thick line).
The order of those elements in each of the output ranges (grey or red) doesn't matter to me. They can be put in any arbitrary order by that function, whatever is simpler to compute for a particular choice of selected input elements (grey). The only thing that matters is that all those selected elements (grey) end up on one side of the boundary, while other elements (red) end up on the other side of that boundary, and the two ranges are continuous.
This function needs to be parametrizable so that, out of all possible permutations of this array, I could choose that particular permutation that puts the elements in that particular order by just specifying some numerical parameter (or parameters) in the function's formula.
One numerical parameter is preferable, since there is only one permutation that puts all the elements in this particular order, and this number could be the "identifying number" of that permutation, but if that would be hard to achieve, several numerical parameters is acceptable, as long as it doesn't exceed the number of chosen elements (which would probably make it not worth the effort anyway).
Is there a way to construct a formula for such a function in a systematic way, given a subset of "chosen elements" from the input array? Maybe something based on modular arithmetics or finite fields? A quick web search gave me a term called "permutation polynomials" that at first glance seems to be related to this problem somehow, but all the resources I could find about them are some thick math that seems to require a lot of background in that field to even understand what's going on (I'm just an IT engineer / programmer looking for a solution for some programming problem, not a professional mathematician :q )
Of course, any function could be put into a lookup table. But that's not what I'm looking for, because that would require a lookup table of the same size as the entire input set, which would be an overkill.
Edit:
One thing that comes to my mind is modular exponentiation, since in prime moduli, when a primitive root is chosen as the base, and the exponent is our $x$, then every power of that base is unique (maximal period) and the resulting sequence is some permutation of the original sequence (however, it always starts and ends with 1, and there's always $N-1$ in the middle). But this way I can only obtain some permutations, not every possible permutation.
Raising this exponential function to some other power $p$ only selects every $p$th element from this sequence, so this way I can only get a sequence for another primitive root (provided that $p$ is coprime to the size of the modulus less one, because otherwise the period breaks into shorter cycles, like for some other base that is not a primitive root). Maybe there is some other way to shuffle those numbers than exponentiation?
 A: As you may know, an invertible (non-singular) $n\times n$ matrix having entries over $F_q$, where q=$p^k$ and $p$ prime defines a finite image space, thus it's a permutation of $F_q^n$. This is, given $M \in GL_n(q)$ where $q=p^k$ and $k\geq 1$, as $M$ is non-singular, it defines a permutation over the tuples in $F_q^n$. This is a consequence of $M$ being an element of the general linear group (invertible matrices) and matrix multiplication being reduced modulo $p$ or $f(x)$ if $F_q$ it's an extension field of degree $n$.
You mentioned Permutation Polynomials over Finite Fields containing $q$ elements. It results that the group of Linearised Permutation Polynomials over $F_{q^n}$ under composition and the group of invertible Matrices over $F_q$ under multiplication are isomorphic. A Linearised Polynomial over $F_{q^n}$ can be defined as $p(X) = \sum_{i=0}^{n-1} \alpha_i x^{q^i} \; \alpha_i \in F_{q^n}$ and we have some mathematic ways to prove if it's a Permutation Polynomial or not.
First, explain the relation between polynomials of degree $n-1$ over $F_q$ and vectors-tuples over $F_q$ of dimension $n$. The map $\varphi$ sends a vector to a polynomial and vice-versa:
$$\varphi : F_q^n \mapsto F_{q^n}$$
$$\varphi(a_0,\ldots,a_{n-1}) \mapsto \sum_{i=0}^{n-1}a_ix^i$$
Now, to establish a relationship between invertible matrices over $F_q$ and Linearised Permutation Polynomials over $F_{q^n}$, we must define the map $\phi$ that sends a Linearised Polynomial $p(X)$ to an invertible matrix $M_{p(X)}$.
$$\phi: \mathcal{L}_n \simeq GL_n(q)$$
$$\phi(p(X)) \mapsto \{\varphi^{-1}(p(\varphi(e_1)),\ldots, \varphi^{-1}(p(\varphi(e_n)))\}$$
Clearly, both maps are linear and agree on the same image by applying $\varphi$ to the input of $p(X)$ and $\varphi^{-1}$ to it's output.
$$M_{p(X)}\cdot \sum_{i=1}^n \alpha_i e_i = \varphi^{-1}(p(\sum_{i=1}^n \varphi(\alpha_i e_i)))$$
$$\sum_{i=1}^n  M_{p(X)} \cdot \alpha_i e_i = \varphi^{-1}(\sum_{i=1}^n p(\varphi(\alpha_i e_i)))$$

In terms of computer science, you don't need to compute Linearised Permutation Polynomials, instead, you can work with invertible square matrices over a prime field, or an extension field of such field. Why? Well, it's been proved that Linearised Permutation Polynomials over $F_{q^n}$ and Invertible Matrices over $F_q$ define an equivalent action by the relationship exposed above. These matrices are elements of the general linear group $GL_n(q)$. This definition, guarantees that, given an invertible matrix $M$ over $F_q$, the operation $M \cdot x = b$ permutes $x$. As a consequence, here multiplication defines a bijection on the set of elements of $F_q$.

There is more work under the branch of combinatorics. For example, the symmetric group on $n$ symbols $S_n$ is comprised of all the permutations of degree $n$. From here, you can calculate the $k$th permutation of a set $S$ having $n$ elements by the decomposition into the Factoradic Number System, which gives you a quotient list that defines that $k$th permutation. Another point, is the one you mentioned, which is based on modular exponentiation. For that, understand that having a big order $r$ s.t $g^r \equiv_p 1$ is satisfied it's quite unpractical for permutations, since you must calculate each image $g^i$ until $g^r$, which is bounded by the length of your set $S$ which is going to be permuted.
