summaryrefslogtreecommitdiff
path: root/src/modules/voronoi
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-05-21 23:27:02 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-05-21 23:27:02 -0700
commitc1fed8c508dd89c86de7dd647de0d014c441344e (patch)
treefac4d327c18fe5a2a205a2f4b4ad7f8287ec3536 /src/modules/voronoi
parente21cdb67718a5d203372fd0c425e8be3e1d273f3 (diff)
modules/*: first stab at utilizing supplied seeds
This is a mostly mechanical change of using rand_r() in place of rand(), using the provided seed as the seed state. There's some outstanding rand()s outside of create_context() which should probably get switched over, with the seed being stowed in the context struct. I didn't bother going deeper on this at the moment in the interests of getting to sleep soon.
Diffstat (limited to 'src/modules/voronoi')
-rw-r--r--src/modules/voronoi/voronoi.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/modules/voronoi/voronoi.c b/src/modules/voronoi/voronoi.c
index 0a9ba70..adb180d 100644
--- a/src/modules/voronoi/voronoi.c
+++ b/src/modules/voronoi/voronoi.c
@@ -42,6 +42,7 @@ typedef struct voronoi_distances_t {
} voronoi_distances_t;
typedef struct voronoi_context_t {
+ unsigned seed;
voronoi_setup_t setup;
voronoi_distances_t distances;
voronoi_cell_t cells[];
@@ -67,12 +68,12 @@ static void voronoi_randomize(voronoi_context_t *ctxt)
for (size_t i = 0; i < ctxt->setup.n_cells; i++) {
voronoi_cell_t *p = &ctxt->cells[i];
- p->origin.x = ((float)rand() * inv_rand_max) * 2.f - 1.f;
- p->origin.y = ((float)rand() * inv_rand_max) * 2.f - 1.f;
+ p->origin.x = ((float)rand_r(&ctxt->seed) * inv_rand_max) * 2.f - 1.f;
+ p->origin.y = ((float)rand_r(&ctxt->seed) * inv_rand_max) * 2.f - 1.f;
- p->color = ((uint32_t)(rand() % 256)) << 16;
- p->color |= ((uint32_t)(rand() % 256)) << 8;
- p->color |= ((uint32_t)(rand() % 256));
+ p->color = ((uint32_t)(rand_r(&ctxt->seed) % 256)) << 16;
+ p->color |= ((uint32_t)(rand_r(&ctxt->seed) % 256)) << 8;
+ p->color |= ((uint32_t)(rand_r(&ctxt->seed) % 256));
}
}
@@ -89,6 +90,7 @@ static void * voronoi_create_context(unsigned seed, unsigned ticks, unsigned n_c
return NULL;
ctxt->setup = *(voronoi_setup_t *)setup;
+ ctxt->seed = seed;
voronoi_randomize(ctxt);
© All Rights Reserved