1 /* Public domain. */ 2 3 #ifndef _LINUX_RANDOM_H 4 #define _LINUX_RANDOM_H 5 6 #include <sys/types.h> 7 #include <sys/systm.h> 8 9 static inline uint32_t 10 get_random_u32(void) 11 { 12 return arc4random(); 13 } 14 15 static inline unsigned int 16 get_random_int(void) 17 { 18 return arc4random(); 19 } 20 21 static inline uint64_t 22 get_random_u64(void) 23 { 24 uint64_t r; 25 arc4random_buf(&r, sizeof(r)); 26 return r; 27 } 28 29 static inline unsigned long 30 get_random_long(void) 31 { 32 #ifdef __LP64__ 33 return get_random_u64(); 34 #else 35 return get_random_u32(); 36 #endif 37 } 38 39 static inline uint32_t 40 prandom_u32_max(uint32_t x) 41 { 42 return arc4random_uniform(x + 1); 43 } 44 45 static inline void 46 get_random_bytes(void *buf, int nbytes) 47 { 48 arc4random_buf(buf, nbytes); 49 } 50 51 #endif 52