diff --git a/include/util.hpp b/include/util.hpp index 004458af..b504bcfe 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -69,7 +69,7 @@ T *construct(F f, V v, Args... args) { //////////////////// /** Seeds the RNG with the current time */ -void randomSeedTime(); +void randomInit(); uint32_t randomu32(); uint64_t randomu64(); /** Returns a uniform random float in the interval [0.0, 1.0) */ diff --git a/src/main.cpp b/src/main.cpp index 8f707823..b20bf30a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,7 @@ using namespace rack; int main(int argc, char* argv[]) { - randomSeedTime(); + randomInit(); #ifdef RELEASE std::string logFilename = assetLocal("log.txt"); diff --git a/src/util.cpp b/src/util.cpp index ae53f039..ed2ba918 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -21,7 +21,7 @@ namespace rack { // xoroshiro128+ // from http://xoroshiro.di.unimi.it/xoroshiro128plus.c -static uint64_t xoroshiro128plus_state[2]; +static uint64_t xoroshiro128plus_state[2] = {}; static uint64_t rotl(const uint64_t x, int k) { return (x << k) | (x >> (64 - k)); @@ -39,7 +39,9 @@ static uint64_t xoroshiro128plus_next(void) { return result; } -void randomSeedTime() { +void randomInit() { + // Only allow the seed to be initialized once during the lifetime of the program. + assert(xoroshiro128plus_state[0] == 0 && xoroshiro128plus_state[1] == 0); struct timeval tv; gettimeofday(&tv, NULL); xoroshiro128plus_state[0] = tv.tv_sec;