C程序生成长度32的随机十六进制字符串
在C语言中生成一个长度为32的十六进制随机字符串;
大致方法为,生成一个十进制的数,然后转换成十六进制字符;
示例源码
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int length = 32;
char str[] = "0123456789abcdef";
//随机种子
srand((unsigned int) time(0) + getpid());
while(length--) {
putchar(str[rand() % 16]);
srand(rand());
}
return 0;
}
输出:
2b2d7913b9af021861f73eda6961b8ca