在看/dev目录下的东西的时候发现有个random的“设备”因为自己是搞加密算法的,对随机数很敏感,所以就试着产生一些随机数。
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
unsigned char buf[512];
int fd = open("/dev/random", O_RDONLY);
if(fd < 0)
{
printf("open err.\n");
return -1;
}
int i;
ssize_t n = read(fd, buf, 16);
for(i=0; i<n; i++)
printf("%02x ", buf[i]);
printf("\n");
}