C语言生成指定长度的字符串密码
在C语言中使用当前时间和进程识别码作为随机种子,生成一个指定长度,内容随机的字符串密码;
实现代码如下:
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
int length = 8; //长度
//随机种子
srand((unsigned int) time(0) + getpid());
while(length--) {
putchar(rand() % 56 + 65);
}
return EXIT_SUCCESS;
}