I am looking for an invertible discrete function $f$ such that given some integer n, if i apply $f(i)$ for $i=0,\dots,n$ I would get all the integers in range $[0..n)$ exactly once, but in a "messy" - "random" if you will manner.
I thought about finding a generator for the group $(\Bbb Z_n,\cdot)$, but im not sure if it would work for any given $n\dots$ (would it?)
any other ideas?
I think what you are talking about is defining $f(i) := x^i$ for $i>0$ and $f(0) = 0$ where $x$ is a generator of the multiplicative group of integers mod $n$ -- called a primitive root. To avoid the predictability of the $f(0)$, you could define $f(0) = a$ and $f(i) = x^i + a$ (mod $n$).This is a good idea, as usually it will give that random-seeming arrangement, but it requires the group in question be cyclic, which is only true if $n =$ 1, 2, 4, $p^k$, or $2p^k$ for prime $p$.