2 * include/linux/random.h
4 * Include file for the random number generator.
6 #ifndef _LINUX_RANDOM_H
7 #define _LINUX_RANDOM_H
10 #include <sys/syscall.h>
11 #include <linux/bug.h>
14 static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
16 return syscall(SYS_getrandom, buf, buflen, flags);
19 extern int urandom_fd;
21 static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
23 return read(urandom_fd, buf, buflen);
27 static inline void get_random_bytes(void *buf, int nbytes)
29 BUG_ON(getrandom(buf, nbytes, 0) != nbytes);
32 static inline int get_random_int(void)
36 get_random_bytes(&v, sizeof(v));
40 static inline long get_random_long(void)
44 get_random_bytes(&v, sizeof(v));
48 #endif /* _LINUX_RANDOM_H */