From b38db01c835fa222aa11ace3a2d84095fe2c3f83 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 20 Jul 2022 21:06:31 -0700 Subject: modules/sparkler: s/rand/rand_r/ and wire up seed This is a little contorted but not too bad. The input to particles_new() is just a const conf struct, so instead of passing in the seed value for particles_t to contain, a pointer to where the seed lives is passed in via the conf. This requires the caller to persist a seed somewhere outside the particles instance, but at least in rototiller we already have that conveniently in til_module_context_t. --- src/modules/sparkler/xplode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules/sparkler/xplode.c') diff --git a/src/modules/sparkler/xplode.c b/src/modules/sparkler/xplode.c index 31f56fd..1534369 100644 --- a/src/modules/sparkler/xplode.c +++ b/src/modules/sparkler/xplode.c @@ -26,8 +26,8 @@ static int xplode_init(particles_t *particles, const particles_conf_t *conf, par { xplode_ctxt_t *ctxt = p->ctxt; - ctxt->decay_rate = rand_within_range(XPLODE_MIN_DECAY_RATE, XPLODE_MAX_DECAY_RATE); - ctxt->lifetime = ctxt->longevity = rand_within_range(XPLODE_MIN_LIFETIME, XPLODE_MAX_LIFETIME); + ctxt->decay_rate = rand_within_range(conf->seedp, XPLODE_MIN_DECAY_RATE, XPLODE_MAX_DECAY_RATE); + ctxt->lifetime = ctxt->longevity = rand_within_range(conf->seedp, XPLODE_MIN_LIFETIME, XPLODE_MAX_LIFETIME); p->props->drag = 10.9; p->props->mass = 0.3; @@ -50,7 +50,7 @@ static particle_status_t xplode_sim(particles_t *particles, const particles_conf if (!(ctxt->lifetime % 30)) { particle_props_t props = *p->props; - props.velocity = (float)rand_within_range(10, 50) / 10000.0; + props.velocity = (float)rand_within_range(conf->seedp, 10, 50) / 10000.0; particles_spawn_particle(particles, p, &props, &xplode_ops); } -- cgit v1.2.1