+/*
+ * See if we should reuse the last seed, if dedupe is enabled
+ */
+static struct frand_state *get_buf_state(struct thread_data *td)
+{
+ uint64_t frand_max;
+ unsigned int v;
+ unsigned long r;
+
+ if (!td->o.dedupe_percentage)
+ return &td->buf_state;
+ else if (td->o.dedupe_percentage == 100) {
+ frand_copy(&td->buf_state_prev, &td->buf_state);
+ return &td->buf_state;
+ }
+
+ frand_max = rand_max(&td->dedupe_state);
+ r = __rand(&td->dedupe_state);
+ v = 1 + (int) (100.0 * (r / (frand_max + 1.0)));
+
+ if (v <= td->o.dedupe_percentage)
+ return &td->buf_state_prev;
+
+ return &td->buf_state;
+}
+
+static void save_buf_state(struct thread_data *td, struct frand_state *rs)
+{
+ if (td->o.dedupe_percentage == 100)
+ frand_copy(rs, &td->buf_state_prev);
+ else if (rs == &td->buf_state)
+ frand_copy(&td->buf_state_prev, rs);
+}
+