I am currently trying to come up with an algoritm which would take at least two numbers (say user IDs) and then come up with an unique number which is generated based on these two numbers. Each integer can be as big as an INT(11) in a Database (a number with 11 digits)
Example: User A (with ID:23, would like to interact with user B (ID: 20) and an unique number out of those two numbers must be generated, say 4094. This number might or might not be reversible back to 23 and 20 (I don't really care) but it's important only these two numbers to always produce this same number. It is very important no matter of the order (23-20, or 20-23) the generated number to be still the same too).
- I was thinking it would be just easier to use some hashing function (SHA2, since MD5 allows collisions).
- I also checked the suggested formula of:
but it does not work when you swap A and B.
- I know this can be done by a database table, which stores the relation between the two tables but I want to avoid this by doing it in the runtime.
Do you have any good ideas for a single math formula which would do the trick for me?