I am searching for a function which has input a number X from 0, 1, 2, 3....N. Its result should be Y which belongs to a permuted version of the input's set.
The results must be unique and thus all of them are generated. Now, I am aware / don't mind that for all lists of 0, 1, .... N, the same results will be outputed. This is expected and fine, I just want the results to be the input shuffled around.
For example: N = 10. I call the function 10 times with: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and it might return 7, 1, 5, 2, 9, 8, 3, 0, 4, 6.
I found this function :
function perm( x )
{
return x * 833 % N;
}
Where 833 can be any large-ish prime number. This makes good-ish results but they are always with a repeating pattern. See for N = 16: 0 3 6 9 12 15 2 5 8 11 14 1 4 7 10 13
Imagine it looks like 3 shark fins. Basically my question is, how do I make a function that does what I have described but with a more chaotic shuffle?
I CANNOT pregenerate a permutation of 0, 1...N.
user73445 X is the nr of already generated values. It represents the number of entries in my database. There is nowhere to put the pregenerated characters, thus when I add another entry in my database, I get the nr of existing entries, generate using the F(x) I seek, and add the entry with the result.
– Discipol Apr 30 '13 at 20:28