Is there an easy way to create a row without duplicates?

I know that I can use a GUID to create a unique string, but it's too long. Now I need to create a non-duplicate line on the website, how can I do this? Thanks!

For example: on the website http://mathurl.com/ you can create a permanent URL, for example http://mathurl.com/75ujy7b and 75ujy7b are very short and not duplicated.

0
source share
2 answers

First of all, you can start with a counter to make sure that with the help of Mutex / lock, which returns unique incremental numbers, you save the last number on your website, possibly in web.config, possibly in a database or in a file.

Then you convert this unique number to another base number, for example, to base-64. Here are some codes and details on how you can do this.

stack overflow

And you can get results like

value: 0 encoded: A value: 1 encoded: B value: 9999999999 encoded: SrYsNt value: 4294965286 encoded: ZNGEvT value: 2292964213 encoded: rHd24J value: 1000000000 encoded: TrNVzD 

Now, if you scramble a card into characters, you can also make it not so easy to find a number.

+2
source

you can use a random number of sufficient length .. between lets say 10,000 and 99,999.

if this suits you enough, you can learn some hashing algorithms .. i think ..

0
source

All Articles