Usually a random permutation for an array with n elements means a uniform distribution from n! possibilities, and the Knuth shuffle is used to do so:
for i from n − 1 downto 1 do
j ← random integer with 0 ≤ j ≤ i
exchange a[j] and a[i]
But with the constraint that a[i] != i, I have no idea how to form such a permutation uniformly.
For example, with n = 3, how to form a permutation randomly from the possibilities below?
{1, 2, 0}, {2, 0, 1}
Permutation without fixed points is called derangement
As the number of derangemets is O(n!), just like the number of permutations, generating all permutations and filtering those which are not derangements wouldn’t hurt your performance.
Quick search returned me these slides, which describe another algorithm.