//产生长度为length的随机字符串
char* genRandomString(int length)
{
int flag, i;
char* string;
srand((unsigned) time(NULL ));
if ((string = (char*) myMalloc(length)) == NULL )
{
myLog("Malloc failed!flag:14\n");
return NULL ;
}
for (i = 0; i < length - 1; i++)
{
flag = rand() % 3;
switch (flag)
{
case 0:
string[i] = 'A' + rand() % 26;
break;
case 1:
string[i] = 'a' + rand() % 26;
break;
case 2:
string[i] = '0' + rand() % 10;
break;
default:
string[i] = 'x';
break;
}
}
string[length - 1] = '\0';
return string;
C语言产生随机字符串
最新推荐文章于 2024-07-15 13:32:43 发布