xref: /plan9/sys/src/cmd/unix/drawterm/libc/truerand.c (revision 8ccd4a6360d974db7bd7bbd4f37e7018419ea908)
1 #include <u.h>
2 #include <libc.h>
3 
4 ulong
truerand(void)5 truerand(void)
6 {
7 	ulong x;
8 	static int randfd = -1;
9 
10 	if(randfd < 0)
11 		randfd = open("/dev/random", OREAD|OCEXEC);
12 	if(randfd < 0)
13 		sysfatal("can't open /dev/random");
14 	if(read(randfd, &x, sizeof(x)) != sizeof(x))
15 		sysfatal("can't read /dev/random");
16 	return x;
17 }
18