-extern void init_rand(struct frand_state *, int);
-extern void init_rand_seed(struct frand_state *, unsigned int seed, int);
+static inline double __rand_0_1(struct frand_state *state)
+{
+ if (state->use64) {
+ uint64_t val = __rand64(&state->state64);
+
+ return (val + 1.0) / (FRAND64_MAX + 1.0);
+ } else {
+ uint32_t val = __rand32(&state->state32);
+
+ return (val + 1.0) / (FRAND32_MAX + 1.0);
+ }
+}
+
+/*
+ * Generate a random value between 'start' and 'end', both inclusive
+ */
+static inline int rand32_between(struct frand_state *state, int start, int end)
+{
+ uint32_t r;
+
+ assert(!state->use64);
+
+ r = __rand32(&state->state32);
+ return start + (int) ((double)end * (r / (FRAND32_MAX + 1.0)));
+}
+
+extern void init_rand(struct frand_state *, bool);
+extern void init_rand_seed(struct frand_state *, unsigned int seed, bool);