Skip to content

Instantly share code, notes, and snippets.

@mmitou
Created November 6, 2012 02:54
Show Gist options
  • Save mmitou/4022267 to your computer and use it in GitHub Desktop.
Save mmitou/4022267 to your computer and use it in GitHub Desktop.
/dev/randomから読み込み
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main() {
const int fd = open("/dev/random",
O_RDONLY);
int i;
if(fd < 0) {
perror("open /dev/radom: ");
return 1;
}
for(i = 0; i < 10; ++i) {
int buf = 0;
const ssize_t size = read(fd, &buf, sizeof(buf));
if(size == sizeof(int)) {
printf("%d: %x\n", i, buf);
} else {
perror("read fail:");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment