C++ 实现http摘要认证之产生任意个数的随机数代码
std::string randomString(const int count){
std::string hexStr = "123456789abcdef";
std::string tmpStr(count, 'a');
std::random_device rd;
std::default_random_engine engine(rd());
std::uniform_int_distribution<> dis(0, 14);
auto dice = std::bind(dis, engine);
// dice()是产生的随机数
for (int i = 0; i<count; i++) {
tmpStr[i] = hexStr[dice()];
}
std::string s = std::string(tmpStr);
return s;
}
程序的运行截图如下: