1 /* $Id: example.c,v 1.1.1.1 2008/01/06 03:24:00 holger Exp $ */
5 #endif /* HAVE_CONFIG_H */
8 #include <stdlib.h> /* For free(3). */
18 if ((fp = fopen("/dev/urandom", "r")) == NULL &&
19 (fp = fopen("/dev/random", "r")) == NULL) {
20 perror("Cannot open random device");
23 if (fread(&random, sizeof(random), 1, fp) != 1) {
24 (void)fputs("Cannot read random device.", stderr);
27 if (fclose(fp) != 0) {
28 perror("Cannot close random device");
32 /* We never heard of printf(3), so we use asprintf(3)/puts(3) :-) */
33 if (asprintf(&buf, "Random %zu-bit integer: %#.*x",
34 sizeof(random) * 8, (int)sizeof(random) * 2, random) < 0) {
35 perror("asprintf(3) failed");