Generating Unique Invoice tracking in dot net

294 views Asked by At

I need to produce a unique tracking number with only 10 digits in length.

as i google the only usefull article from stackoverflow Generating unique tracking numbers

but this is not dot net code. i try to find find a way to write dot net equivelant of this code but i can not do it.

>>> int(hashlib.sha256(str(1) + "!salt!").hexdigest()[:13], 16)
1269883740611281
>>> int(hashlib.sha256(str(2) + "!salt!").hexdigest()[:13], 16)
3655373802716929

can anyone help me?

1

There are 1 answers

0
usr On

I don't know why the code that you are using there uses a hash. Hash values are not unique. The hash seems to be misused here as a random number generator. Instead, use an RNG directly:

new Random().Next(1000 * 1000 *1000, 1000 * 1000 *1000 * 10).ToString()

You can use web search to find a cryptographically strong way to generate random numbers in that range.

You can have more possible tracking codes by using letters as well.