如何用C语言产生一个随机的字符串
1个回答
展开全部
//----RandStr.c----
//aimming for producing Random String
#include <stdlib.h>
#include <stdio.h>
#define N 50
int main()
{
char stencil[53] = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM";
char RandStr[N];
long RandNum;
for (long i = 0; i < N; i++)
{
RandStr[i] = '\0';
RandNum = rand() % 11 + 10;//The RandStr number From 10 To 20.
for (long i = 0; i < RandNum; i++)
RandStr[i] = stencil[rand() % 52];//All STENCIL-PLATE number: 53.
}
printf("This is a random string:%s\n",RandStr);
return 0;
}
//aimming for producing Random String
#include <stdlib.h>
#include <stdio.h>
#define N 50
int main()
{
char stencil[53] = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM";
char RandStr[N];
long RandNum;
for (long i = 0; i < N; i++)
{
RandStr[i] = '\0';
RandNum = rand() % 11 + 10;//The RandStr number From 10 To 20.
for (long i = 0; i < RandNum; i++)
RandStr[i] = stencil[rand() % 52];//All STENCIL-PLATE number: 53.
}
printf("This is a random string:%s\n",RandStr);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询