C++ – Generating a unique id of std::string


I want to generate any limited std::string size unique id (i.e of size 6) in 32 bit application. what would be the best and quick way to do this?

Best Solution

Look up hashing of strings, e.g. the Jenkins hash function.

But you will never get unique hashes, because strings can be much longer than your size 6, and the Pigoenhole lemma shows trivially that hashes must collide as a a consequence.