diff options
author | Mitya Selivanov <0x7fffff@guattari.ru> | 2022-08-30 09:14:07 +0400 |
---|---|---|
committer | Mitya Selivanov <0x7fffff@guattari.ru> | 2022-08-30 09:14:07 +0400 |
commit | d4651589b3b392a11a256452813ee7d7396cdf85 (patch) | |
tree | 88437c701bdb88c3b92695b186525a3400177ef7 | |
parent | 4386f1f005c73f9fd99f90f618b554be341f76f8 (diff) | |
download | kit-d4651589b3b392a11a256452813ee7d7396cdf85.zip |
[mt64] kit_mt64_init_array
-rw-r--r-- | source/kit/mersenne_twister_64.c | 16 | ||||
-rw-r--r-- | source/kit/mersenne_twister_64.h | 4 |
2 files changed, 16 insertions, 4 deletions
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 |