Obscure / encrypt an order number as another number: symmetrical, “random” appearance?

后端 未结 7 523
长情又很酷
长情又很酷 2020-12-13 02:44

Client has an simple increasing order number (1, 2, 3...). He wants end-users to receive an 8- or 9- digit (digits only -- no characters) \"random\" number. Obviously, this

7条回答
  •  余生分开走
    2020-12-13 03:20

    In 9 digit number, the first digit is a random index between 0 and 7 (or 1-8). Put another random digit at that position. The rest is the "real order number:

    • Orig order: 100
    • Random index: 5
    • Random digit: 4 (guaranteed, rolled a dice :) )
    • Result: 500040100

    • Orig Nr: 101

    • Random index: 2
    • Random digit 6
    • Result: 200001061

    You can decide that the 5th (or any other) digit is the index.

    Or, if you can live with real order numbers of 6 digits, then you can introduce "secondary" index as well. And you can reverse the order of the digits in the "real" order nr.

提交回复
热议问题