#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
char *rand_str(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 name[20];
cout<<rand_str(name,20)<<endl;
system("pause");
return 0;
}
604随机字符串组合产生
最新推荐文章于 2023-06-27 13:52:45 发布
本文介绍了一个简单的C++程序,该程序能够生成包含大写字母、小写字母和数字的随机字符串。通过使用srand和rand函数配合time函数,确保了每次运行程序时都能得到不同的随机字符串。
1127

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



