#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
char pool[] = {
'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','A','B','C','D',
'E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X',
'Y','Z'
}; //随机池
int main(){
// srand(time(0));
/*
使用 time(0) 做种子,在一秒之内种子是不会变的
通过使用微妙,来增加随机数的随机性
*/
struct timeval tpstart;
gettimeofday(&tpstart,NULL);
srand(tpstart.tv_usec);
char pwd[9];
pwd[8] = '\0';
int i = 0;
while(i != 8){
pwd[i++] = pool[rand()%sizeof(pool)];
}
printf("%s\n",pwd);
return 0;
}
linux c 生成八位的随机密码
最新推荐文章于 2022-09-27 17:10:40 发布