summaryrefslogtreecommitdiff
path: root/generators.c
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2014-06-29 12:06:36 -0500
committerBobby Bingham <koorogi@koorogi.info>2014-06-29 12:10:20 -0500
commit0de853d851d68c57689c44812447d20b83ab5caa (patch)
treef6d252595aed77e672a281379d5c935db8dcf7a0 /generators.c
parent979579d81aa3842263dcf909363fd1dc971ea767 (diff)
Add generator of mostly sorted data
Diffstat (limited to 'generators.c')
-rw-r--r--generators.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/generators.c b/generators.c
index c4a70a0..2e31b72 100644
--- a/generators.c
+++ b/generators.c
@@ -38,10 +38,26 @@ static void generate_constant(int *buffer, size_t size)
for (size_t i = 0; i < size; i++) buffer[i] = 42;
}
+static void generate_sorted_noise(int *buffer, size_t size)
+{
+ int noisemax = size / 4;
+ int noiseoff = size / 8;
+
+ srandom(1);
+ for (size_t i = 0; i < size; i++) {
+ int noise = 0;
+ if (random() < 0.2 * RAND_MAX) {
+ noise = random() % noisemax - noiseoff;
+ }
+ buffer[i] = i + noise;
+ }
+}
+
const struct generator generators[] = {
- { .name = "random", .func = generate_random },
- { .name = "sorted", .func = generate_sorted },
- { .name = "reverse", .func = generate_reverse },
- { .name = "constant", .func = generate_constant },
+ { .name = "random", .func = generate_random },
+ { .name = "sorted", .func = generate_sorted },
+ { .name = "reverse", .func = generate_reverse },
+ { .name = "constant", .func = generate_constant },
+ { .name = "sorted+noise", .func = generate_sorted_noise },
{ 0 }
};