From c69917862a58cac01d9deca2b91255f0510b243c Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 20 Jul 2022 21:49:37 -0700 Subject: modules/pixbounce: s/rand/rand_r/ Wire up seed via til_module_context.seed in the obvious manner, minimal change to the code, no functional difference besides giving pixbounces instances an isolated random seed state. --- src/modules/pixbounce/pixbounce.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/modules/pixbounce/pixbounce.c b/src/modules/pixbounce/pixbounce.c index 206d8a2..d200ad6 100644 --- a/src/modules/pixbounce/pixbounce.c +++ b/src/modules/pixbounce/pixbounce.c @@ -235,9 +235,9 @@ typedef struct pixbounce_context_t { int multiplier; } pixbounce_context_t; -static uint32_t pick_color() +static uint32_t pick_color(unsigned *seedp) { - return makergb(rand()%256, rand()%256, rand()%256, 1); + return makergb(rand_r(seedp)%256, rand_r(seedp)%256, rand_r(seedp)%256, 1); } static til_module_context_t * pixbounce_create_context(unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) @@ -253,7 +253,7 @@ static til_module_context_t * pixbounce_create_context(unsigned seed, unsigned t ctxt->x_dir = 0; ctxt->y_dir = 0; ctxt->pix = &pixbounce_pixmap[((pixbounce_setup_t *)setup)->pixmap]; - ctxt->color = pick_color(); + ctxt->color = pick_color(&ctxt->til_module_context.seed); ctxt->pixmap_size_factor = ((((pixbounce_setup_t *)setup)->pixmap_size)*55 + 22 )/ 100; ctxt->multiplier = 1; @@ -284,10 +284,10 @@ static void pixbounce_render_fragment(til_module_context_t *context, unsigned ti } /* randomly initialize location and direction of pixmap */ - ctxt->x = rand() % (width - ctxt->pix->width * ctxt->multiplier) + 1; - ctxt->y = rand() % (height - ctxt->pix->height * ctxt->multiplier) + 1; - ctxt->x_dir = (rand() % 7) - 3; - ctxt->y_dir = (rand() % 7) - 3; + ctxt->x = rand_r(&ctxt->til_module_context.seed) % (width - ctxt->pix->width * ctxt->multiplier) + 1; + ctxt->y = rand_r(&ctxt->til_module_context.seed) % (height - ctxt->pix->height * ctxt->multiplier) + 1; + ctxt->x_dir = (rand_r(&ctxt->til_module_context.seed) % 7) - 3; + ctxt->y_dir = (rand_r(&ctxt->til_module_context.seed) % 7) - 3; } @@ -309,11 +309,11 @@ static void pixbounce_render_fragment(til_module_context_t *context, unsigned ti /* update pixmap location */ if(ctxt->x+ctxt->x_dir < 0 || ctxt->x+ctxt->pix->width*ctxt->multiplier+ctxt->x_dir > width) { ctxt->x_dir = ctxt->x_dir * -1; - ctxt->color = pick_color(); + ctxt->color = pick_color(&ctxt->til_module_context.seed); } if(ctxt->y+ctxt->y_dir < 0 || ctxt->y+ctxt->pix->height*ctxt->multiplier+ctxt->y_dir > height) { ctxt->y_dir = ctxt->y_dir * -1; - ctxt->color = pick_color(); + ctxt->color = pick_color(&ctxt->til_module_context.seed); } ctxt->x = ctxt->x+ctxt->x_dir; ctxt->y = ctxt->y+ctxt->y_dir; -- cgit v1.2.3