]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/prandom.h
9aea22dc92e745c71e3cc4d686c8a169498c555f
[bcachefs-tools-debian] / include / linux / prandom.h
1 #ifndef _LINUX_PRANDOM_H
2 #define _LINUX_PRANDOM_H
3
4 #include <linux/random.h>
5
6 static inline void prandom_bytes(void *buf, int nbytes)
7 {
8         return get_random_bytes(buf, nbytes);
9 }
10
11 #define prandom_type(type)                              \
12 static inline type prandom_##type(void)                 \
13 {                                                       \
14         type v;                                         \
15                                                         \
16         prandom_bytes(&v, sizeof(v));                   \
17         return v;                                       \
18 }
19
20 prandom_type(int);
21 prandom_type(long);
22 prandom_type(u32);
23 prandom_type(u64);
24 #undef prandom_type
25
26 static inline u32 prandom_u32_max(u32 max)
27 {
28         return prandom_u32() % max;
29
30 }
31
32 #endif /* _LINUX_PRANDOM_H */
33