One-to-one integer mapping function

前端 未结 5 1809
予麋鹿
予麋鹿 2020-12-15 23:50

We are using MySQL and developing an application where we\'d like the ID sequence not to be publicly visible... the IDs are hardly top secret and there is no significant iss

5条回答
  •  抹茶落季
    2020-12-16 00:37

    You could simply XOR with 0xDEADBEEF, if that's good enough.

    Alternatively multiply by an odd number mod 2^32. For the inverse mapping just multiply by the multiplicative inverse

    Example: n = 2345678901; multiplicative inverse (mod 2^32): 2313902621 For the mapping just multiply by 2345678901 (mod 2^32):

    1 --> 2345678901 2 --> 396390506

    For the inverse mapping, multiply by 2313902621.

提交回复
热议问题