summaryrefslogtreecommitdiff
path: root/source/kit/mersenne_twister_64.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/kit/mersenne_twister_64.c')
-rw-r--r--source/kit/mersenne_twister_64.c16
1 files changed, 12 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;