diff options
Diffstat (limited to 'include/linux/random.h')
-rw-r--r-- | include/linux/random.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/include/linux/random.h b/include/linux/random.h index 4002b3df4c85..1cfce0e24dbd 100644 --- a/include/linux/random.h +++ b/include/linux/random.h | |||
@@ -8,7 +8,6 @@ | |||
8 | 8 | ||
9 | #include <uapi/linux/random.h> | 9 | #include <uapi/linux/random.h> |
10 | 10 | ||
11 | |||
12 | extern void add_device_randomness(const void *, unsigned int); | 11 | extern void add_device_randomness(const void *, unsigned int); |
13 | extern void add_input_randomness(unsigned int type, unsigned int code, | 12 | extern void add_input_randomness(unsigned int type, unsigned int code, |
14 | unsigned int value); | 13 | unsigned int value); |
@@ -38,6 +37,23 @@ struct rnd_state { | |||
38 | u32 prandom_u32_state(struct rnd_state *state); | 37 | u32 prandom_u32_state(struct rnd_state *state); |
39 | void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes); | 38 | void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes); |
40 | 39 | ||
40 | /** | ||
41 | * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro) | ||
42 | * @ep_ro: right open interval endpoint | ||
43 | * | ||
44 | * Returns a pseudo-random number that is in interval [0, ep_ro). Note | ||
45 | * that the result depends on PRNG being well distributed in [0, ~0U] | ||
46 | * u32 space. Here we use maximally equidistributed combined Tausworthe | ||
47 | * generator, that is, prandom_u32(). This is useful when requesting a | ||
48 | * random index of an array containing ep_ro elements, for example. | ||
49 | * | ||
50 | * Returns: pseudo-random number in interval [0, ep_ro) | ||
51 | */ | ||
52 | static inline u32 prandom_u32_max(u32 ep_ro) | ||
53 | { | ||
54 | return (u32)(((u64) prandom_u32() * ep_ro) >> 32); | ||
55 | } | ||
56 | |||
41 | /* | 57 | /* |
42 | * Handle minimum values for seeds | 58 | * Handle minimum values for seeds |
43 | */ | 59 | */ |