diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-05-21 23:27:02 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-05-21 23:27:02 -0700 |
commit | c1fed8c508dd89c86de7dd647de0d014c441344e (patch) | |
tree | fac4d327c18fe5a2a205a2f4b4ad7f8287ec3536 /src/modules/snow | |
parent | e21cdb67718a5d203372fd0c425e8be3e1d273f3 (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/snow')
-rw-r--r-- | src/modules/snow/snow.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/modules/snow/snow.c b/src/modules/snow/snow.c index 82ad847..bf0aee0 100644 --- a/src/modules/snow/snow.c +++ b/src/modules/snow/snow.c @@ -10,8 +10,8 @@ /* This implements white noise / snow just using rand() */ typedef union snow_seed_t { - char __padding[256]; /* prevent seeds sharing a cache-line */ - int seed; + char __padding[256]; /* prevent seeds sharing a cache-line */ + unsigned seed; } snow_seed_t; typedef struct snow_context_t { @@ -29,7 +29,7 @@ static void * snow_create_context(unsigned seed, unsigned ticks, unsigned n_cpus return NULL; for (unsigned i = 0; i < n_cpus; i++) - ctxt->seeds[i].seed = rand(); + ctxt->seeds[i].seed = rand_r(&seed); return ctxt; } @@ -50,7 +50,7 @@ static void snow_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, t static void snow_render_fragment(void *context, unsigned ticks, unsigned cpu, til_fb_fragment_t *fragment) { snow_context_t *ctxt = context; - int *seed = &ctxt->seeds[cpu].seed; + unsigned *seed = &ctxt->seeds[cpu].seed; for (unsigned y = fragment->y; y < fragment->y + fragment->height; y++) { for (unsigned x = fragment->x; x < fragment->x + fragment->width; x++) { |