#include <iostream>
using namespace std;
#include <cstdlib>
#include <ctime>
#include <string>
void myrand(string &str,int leng)
{
srand(int(time(0)));//产生随机种子,保证每次的数据都不重复
char temp= '0';
for (int i = 0; i < leng; i++)
{
switch (rand() % 3)
{
case 0:
temp = rand() % 10 + '0';
break;
case 1:
temp = rand() % 26 + 'a';
break;
case 2:
temp = rand() % 26 + 'A';
break;
}
str += temp;
}
}
int main()
{
string str;
myrand(str,4);
cout <<str <<endl;
return 0;
}
C++利用随机数生成验证码
C++随机字符串生成器
最新推荐文章于 2023-07-12 14:05:58 发布
本文介绍了一个使用C++编写的简单随机字符串生成器。该生成器能够创建包含数字、小写字母及大写字母的随机字符串。通过设置字符串长度,可以灵活地生成不同长度的随机字符串。
2887

被折叠的 条评论
为什么被折叠?



