分类: C/C++
2009-10-21 13:56:12
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char * rand_str(int in_len)
{
char *__r = (char *)malloc(in_len + 1);
int i;
if (__r == 0)
{
return 0;
}
srand(time(NULL) + rand()); //初始化随机数的种子
for (i = 0; i < in_len; i++)
{
__r[i] = rand()%94+32; //控制得到的随机数为可显示字符
}
__r[i] = 0;
return __r;
}
void main()
{
int i=0;
while(i++<10)
{
char *p = rand_str(15);
printf("group %02d: %s\n", i, p);
free(p);
}
}