#include <iostream>
#include <stdlib.h>
#include <time.h>
char *generateRandString(char *str, const int len)
{
// 产生随机数
srand(time(NULL));
int i;
for (i = 0; i < len; ++i)
{
switch ((rand() % 3))
{
case 1:
str[i] = 'A' + rand() % 26;
break;
case 2:
str[i] = 'a' + rand() % 26;
break;
default:
str[i] = '0' + rand() % 10;
break;
}
}
str[++i] = '\0';
return str;
}
int main(void)
{
char buffer[8];
// 生成一个4位随机字符串
std::cout << generateRandString(buffer, 4) << std::endl;
system("pause");
return 0;
}