random: Add arch_has_random[_seed]()
[cascardo/linux.git] / include / linux / random.h
index 4002b3d..57fbbff 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <uapi/linux/random.h>
 
-
 extern void add_device_randomness(const void *, unsigned int);
 extern void add_input_randomness(unsigned int type, unsigned int code,
                                 unsigned int value);
@@ -38,6 +37,23 @@ struct rnd_state {
 u32 prandom_u32_state(struct rnd_state *state);
 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
 
+/**
+ * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
+ * @ep_ro: right open interval endpoint
+ *
+ * Returns a pseudo-random number that is in interval [0, ep_ro). Note
+ * that the result depends on PRNG being well distributed in [0, ~0U]
+ * u32 space. Here we use maximally equidistributed combined Tausworthe
+ * generator, that is, prandom_u32(). This is useful when requesting a
+ * random index of an array containing ep_ro elements, for example.
+ *
+ * Returns: pseudo-random number in interval [0, ep_ro)
+ */
+static inline u32 prandom_u32_max(u32 ep_ro)
+{
+       return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
+}
+
 /*
  * Handle minimum values for seeds
  */
@@ -72,6 +88,22 @@ static inline int arch_get_random_int(unsigned int *v)
 {
        return 0;
 }
+static inline int arch_has_random(void)
+{
+       return 0;
+}
+static inline int arch_get_random_seed_long(unsigned long *v)
+{
+       return 0;
+}
+static inline int arch_get_random_seed_int(unsigned int *v)
+{
+       return 0;
+}
+static inline int arch_has_random_seed(void)
+{
+       return 0;
+}
 #endif
 
 /* Pseudo random number generator from numerical recipes. */