Create a random bijective function which has same

2019-07-28 23:36发布

问题:

Create a random bijective function which has same domain and range. By random bijective function I mean a function which maps the elements from domain to range using a random algorithm (or at least a pseudo-random algo), and not something like x=y. The domain and range can be a very small set sometimes like {1,2,3,4,5}, so a pairing function won't work. Also, computational resources are limited, so it should be a computationaly feasible function.

Edit: What I meant in the question was, say you have a list of 5 numbers A = {1,2,3,4,5}. Now what you want to do is create a random function f which when applied to the above set gives a set containing the same above numbers, but in a different order with a sufficiently high probability. Like if I did f(A) = B, then B could be {2,4,1,5,3}. So A to B maping is 1->2, 2->4, 4->1, 4->5 and 5 ->3. But if I did f(A) again then the mapping this time should be another such randomised one i.e. if f(A) = C, then C could be any one of the possible permutations of A with uniformly equal probability. This can easily be achieved by calculating the nth permutation. But what my doubt is that if I want to find out the mapping of a number from the set A in a given specific time interval, then can it be done in constant time and space.

回答1:

Well, classical Linear Congruential Generator has this property if it satisfies Hull-Dobell Theorem.

For example, Knuth LCG (a=6364136223846793005, c=1442695040888963407) will map 1:1 domain [0...264) to co-domain [0...264)