How to generate a numeric or string id(not very large text) for a sequence of elements where ordering doesn't matter.

[41,1001,32] should generate the same ID as [32,1001,41]
[41,1001,32, 5] should be different.

Elements could be hundreds where each individual ID can be a 4/5-digit number.

I thought about sorting, concatenate and Hash/Compress the string, but are there gonna be a lot of collisions ?

Any ideas would be much appreciated.


1 Answer 1


If you don't care about the length of the id, sort the list and use that as the id.

If you do care about its length, sort the list and then use the SHA256 hash of the sorted list as the id. It is believed to be infeasible to find collisions for SHA256, so you shouldn't have to worry about collisions. If you find one, publish it and you'll be famous (briefly).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.