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?
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.
Very difficult to tell from your question what you are asking, but the following generates strings in the sequence "1", "2", "3":
#include <string>
#include <sstream>
std::string GetUniqueId() {
static int n = 1;
std::ostringstream os;
os << n++;
return os.str();
}
精彩评论