extern char szLog[32];
char szLog[32]={0};
static unsigned long next = 1;
/* RAND_MAX assumed to be 32767 */
int myrand(void) {
next = next * 1103515245 + 12345;
return((unsigned)(next/65536) % 32768);
}
void mysrand(unsigned seed) {
next = seed;
}
void GenerateDiffNumber(int *diff,int maxn,int num)
{
int rnd=0;
int *tmp=NULL;
tmp = (int *)malloc(sizeof(int)*maxn);
for (int i = 0; i < maxn; i++)
{
tmp[i] = i;
}
for (int i = 0; i < num; i++)
{
int seed=(int)(tmp+rnd);
do
{
rnd = rand() % maxn;
} while (tmp[rnd]==-1);
diff[i] = rnd;
tmp[rnd] = -1;
}
free(tmp);
}
void test()
{
char names[]="zqwertyujiopk123456jhgf4567azxcvbnm";
int n=strlen(names);
int a[128];
GenerateDiffNumber(a,n,17);
int t=time(NULL) ;
for (int i=0;i<17;i++)
{
int j=a[i];
char ch=names[j];
szLog[i]=ch;
}
printf("\nszLog:%s\n",szLog);
}
生成随机字符串
最新推荐文章于 2020-12-21 10:33:38 发布