summaryrefslogtreecommitdiff
path: root/generators.c
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2014-07-06 16:15:44 -0500
committerBobby Bingham <koorogi@koorogi.info>2014-07-06 16:15:44 -0500
commit426847c4e97ce225931bfde275b9e54a6bffe149 (patch)
tree7ae1841582486816c20555d20fb38269b2fc3c16 /generators.c
parente0bdb91c26bd7c82f0ffc050256e5c354adef5ce (diff)
Add a generator for slightly noisy reverse order data
Diffstat (limited to 'generators.c')
-rw-r--r--generators.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/generators.c b/generators.c
index 2e31b72..4c73454 100644
--- a/generators.c
+++ b/generators.c
@@ -38,26 +38,37 @@ 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)
+static void add_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] += random() % noisemax - noiseoff;
}
- buffer[i] = i + noise;
}
}
+static void generate_sorted_noise(int *buffer, size_t size)
+{
+ generate_sorted(buffer, size);
+ add_noise(buffer, size);
+}
+
+static void generate_reverse_noise(int *buffer, size_t size)
+{
+ generate_reverse(buffer, size);
+ add_noise(buffer, size);
+}
+
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 = "sorted+noise", .func = generate_sorted_noise },
+ { .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 },
+ { .name = "reverse+noise", .func = generate_reverse_noise },
{ 0 }
};