From d4651589b3b392a11a256452813ee7d7396cdf85 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov <0x7fffff@guattari.ru> Date: Tue, 30 Aug 2022 09:14:07 +0400 Subject: [mt64] kit_mt64_init_array --- source/kit/mersenne_twister_64.c | 16 ++++++++++++---- source/kit/mersenne_twister_64.h | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/kit/mersenne_twister_64.c b/source/kit/mersenne_twister_64.c index 9ab39d3..c8bbbe2 100644 --- a/source/kit/mersenne_twister_64.c +++ b/source/kit/mersenne_twister_64.c @@ -2,9 +2,12 @@ #include "time.h" -void kit_mt64_init(kit_mt64_state_t *state, uint64_t seed) { - state->mt[0] = seed; - for (state->index = 1; state->index < KIT_MT64_N; state->index++) +void kit_mt64_init_array(kit_mt64_state_t *const state, + ptrdiff_t const size, + uint64_t const *const seed) { + for (ptrdiff_t i = 0; i < size && i < KIT_MT64_N; i++) + state->mt[i] = seed[i]; + for (state->index = size; state->index < KIT_MT64_N; state->index++) state->mt[state->index] = (6364136223846793005ull * (state->mt[state->index - 1] ^ (state->mt[state->index - 1] >> @@ -12,7 +15,12 @@ void kit_mt64_init(kit_mt64_state_t *state, uint64_t seed) { state->index); } -uint64_t kit_mt64_generate(kit_mt64_state_t *state) { +void kit_mt64_init(kit_mt64_state_t *const state, + uint64_t const seed) { + kit_mt64_init_array(state, 1, &seed); +} + +uint64_t kit_mt64_generate(kit_mt64_state_t *const state) { static uint64_t const mag01[2] = { 0ull, 0xB5026F5AA96619E9ull }; int i; diff --git a/source/kit/mersenne_twister_64.h b/source/kit/mersenne_twister_64.h index 416ef27..fb509c2 100644 --- a/source/kit/mersenne_twister_64.h +++ b/source/kit/mersenne_twister_64.h @@ -17,6 +17,9 @@ typedef struct { uint64_t index; } kit_mt64_state_t; +void kit_mt64_init_array(kit_mt64_state_t *state, ptrdiff_t size, + uint64_t const *seed); + void kit_mt64_init(kit_mt64_state_t *state, uint64_t seed); uint64_t kit_mt64_generate(kit_mt64_state_t *state); @@ -25,6 +28,7 @@ uint64_t kit_mt64_seed(); #ifndef KIT_DISABLE_SHORT_NAMES # define mt64_state_t kit_mt64_state_t +# define mt64_init_array kit_mt64_init_array # define mt64_init kit_mt64_init # define mt64_generate kit_mt64_generate # define mt64_seed kit_mt64_seed -- cgit v1.2.3