Created
April 28, 2012 03:30
-
-
Save zhpengg/2515453 to your computer and use it in GitHub Desktop.
使用/dec/random获取64bit随机数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <stdint.h> | |
#include <inttypes.h> | |
int main() | |
{ | |
uint64_t rand64; | |
for (int i = 0; i < 50; i++) { | |
int rfd = open("/dev/random", O_RDONLY, S_IRUSR); | |
if (rfd < 0) { | |
perror("open"); | |
exit(-1); | |
} | |
read(rfd, &rand64, sizeof(rand64)); | |
printf("%"PRIu64"\n", rand64); | |
close(rfd); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment