Tailsy wrote: Although it will rather be a bit more than one line to calculate the correct coefficients for this function when changing the folder.
This is not a big problem, as the coefficients can already be determined at the compilation stage.
A function of the form f(x) = (a*x + b) mod N is differentiable when a and N are relatively prime. It is therefore sufficient to find the minimum prime number p greater than N/2.
Wanting to fit the calculation in 32-bit variables we get a maximum number of files equal to 2^16 = 65536, N/2=32768.
The smallest prime number greater than N/2 is pmin=32771. The largest prime number less than N/2 is pmax=32749.
What remains is the choice of the parameter b, which can be equal to, for example, b=13.
So we have the function f(x) = (32771*x + 13) mod N. For small values of N we get permutations:
From these examples you can see that with each change of N the order of the elements changes, without any change in the parameters a and b.
It can then be tested whether for each i from 1 to N the bijection is preserved. Using Dirichlet's principle, this can be tested with a function:
For the given parameters, it confirms that over the entire range from 1 to N each element occurs exactly once - each piece is played once and none is missed.
It is then possible to check how the function behaves when a=pmax, i.e. when the relative precedence condition is not maintained f(x) = (32749*x + 13) mod N.
The test shows that for N=32749 the function is not differentiable.
The question of the representation of the numbering of the files in the directories remains, it may look like x=directory no*1000 + file no, inverse operations noDirectory=x/1000, file no=x mod 1000.
khoam wrote: Function with "one-line" modulo operation does not guarantee permutation without repetition
Where did you get this from?
khoam wrote: The Feistel network is a legitimate choice for permutations without repetition in limited memory and does not require "manual" selection of this multiplier
For that, it requires some magic numbers, the meaning of which you would not be able to give without the help of AI