Skip to content

Instantly share code, notes, and snippets.

@zhpengg
Created April 28, 2012 03:30
Show Gist options
  • Save zhpengg/2515453 to your computer and use it in GitHub Desktop.
Save zhpengg/2515453 to your computer and use it in GitHub Desktop.
使用/dec/random获取64bit随机数
#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