From c1fed8c508dd89c86de7dd647de0d014c441344e Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 21 May 2022 23:27:02 -0700 Subject: 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. --- src/modules/meta2d/meta2d.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/modules/meta2d') diff --git a/src/modules/meta2d/meta2d.c b/src/modules/meta2d/meta2d.c index 8b87804..d1063de 100644 --- a/src/modules/meta2d/meta2d.c +++ b/src/modules/meta2d/meta2d.c @@ -78,8 +78,9 @@ static void * meta2d_create_context(unsigned seed, unsigned ticks, unsigned n_cp for (int i = 0; i < META2D_NUM_BALLS; i++) { meta2d_ball_t *ball = &ctxt->balls[i]; + /* TODO: add _r() variants of v[23]f_rand()? */ v2f_rand(&ball->position, &(v2f_t){-.7f, -.7f}, &(v2f_t){.7f, .7f}); - ball->radius = rand() / (float)RAND_MAX * .2f + .05f; + ball->radius = rand_r(&seed) / (float)RAND_MAX * .2f + .05f; v3f_rand(&ball->color, &(v3f_t){0.f, 0.f, 0.f}, &(v3f_t){1.f, 1.f, 1.f}); } -- cgit v1.2.3