#include<stdio.h>
char RandString();
int main( void )
{
int i=0;
char cTemp;
char sKey[9];
memset(&cTemp, 0, sizeof(cTemp));
memset(sKey, 0, sizeof(sKey));
srand((unsigned )time(NULL));
for(; i<8; i++)
{
cTemp = RandString();
sKey[i] = cTemp;
}
sKey[8]=‘\0‘;
printf("sKey[%s]\n", sKey);
return 0;
}
char RandString()
{
int j = rand()%2;
char temp;
int m = 0;
if( j==0 )
{
temp =‘a‘;
}
else
{
temp=‘A‘;
}
m = rand()%26;
temp = temp + m;
return temp;
}
运行结果:
sKey[ycePuTLP]
随机生成26个小写字母和26个大写字母
时间: 2024-12-09 09:53:20