Answers
C++代码,利用set集合的特性,速度可以接受。其中使用了一个Random的函数,输入n,返回的值在区间[0,n]
static char codeData[] = {
'1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L',
'M','N','P','Q','R','S','T','U','V','W','X','Y','Z'};
int totalCount = 10000000;
int codeLen = 16;
string prefix = "XX";
int rnd = sizeof(codeData)-1;
std::set<std::string> codes;
std::string code;
while(codes.size() < totalCount) {
code = prefix;
for(int i=0; i<codeLen; i++) {
code.append(1, codeData[Random(rnd)]);
}
codes.insert(code);
}
如果数量确实太大内存不够可以换成hashset再不够可以改用berkerly db提供的set
蛇喰夢子ㅇ
answered 12 years, 6 months ago