Blob
1 #include <u.h>2 #include <libc.h>4 ulong5 truerand(void)6 {7 int i, n;8 uchar buf[sizeof(ulong)];9 static int randfd = -1;11 if(randfd < 0){12 randfd = open("/dev/random", OREAD);13 fcntl(randfd, F_SETFD, FD_CLOEXEC);14 }15 if(randfd < 0)16 sysfatal("can't open /dev/random: %r");17 for(i=0; i<sizeof(buf); i += n)18 if((n = readn(randfd, buf+i, sizeof(buf)-i)) < 0)19 sysfatal("can't read /dev/random: %r");20 return *((ulong*)buf);21 }