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?
C++ – Generating a unique id of std::string
c++
Related Question
- C++ – Why is “using namespace std;” considered bad practice
- C++ – the copy-and-swap idiom
- C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming
- C++ – C++ programmers minimize use of ‘new’
- C++ – std::string to char*
- C++ – How to convert a std::string to int
- C++ – Compiling an application for use in highly radioactive environments
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.