From 643148737f38151d7bfdec1ad45718f5616e0ac9 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 12 Sep 2020 16:26:44 -0700 Subject: modules/spiro: use ticks instead of time() w/srand time() only changes every second, so this had the effect of freezing the seed a second at a time, affecting all rand() users, when spiro's create_context() was called more frequently than 1HZ. When using rtv with channels=spiro,duration=0 the create_context() gets called every other frame, and the visual results were very broken with the spiro only actually reseeding every second and the snow between each frame being static since it too uses rand() for seeding itself. This whole situation suggests no module should be calling srand(), and instead rototiller should probably call srand() once at startup and any modules that wish to use rand with a different seed should use rand_r(), and maybe rand() just for acquiring the seed like modules/snow does. --- src/modules/spiro/spiro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/modules/spiro/spiro.c b/src/modules/spiro/spiro.c index b404c75..6234744 100644 --- a/src/modules/spiro/spiro.c +++ b/src/modules/spiro/spiro.c @@ -37,7 +37,7 @@ static void * spiro_create_context(unsigned ticks, unsigned num_cpus) if (!ctxt) return NULL; - srand(time(NULL) + getpid()); + srand(ticks + getpid()); ctxt->r=.25f+(rand()/(float)RAND_MAX)*.5f; if(ctxt->r>.5f) -- cgit v1.2.3