Browse Source

Rename randomSeedTime to randomInit and assert that it's called only

once
pull/1639/head
Andrew Belt 6 years ago
parent
commit
7c2e8c6780
3 changed files with 6 additions and 4 deletions
  1. +1
    -1
      include/util.hpp
  2. +1
    -1
      src/main.cpp
  3. +4
    -2
      src/util.cpp

+ 1
- 1
include/util.hpp View File

@@ -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) */


+ 1
- 1
src/main.cpp View File

@@ -11,7 +11,7 @@
using namespace rack;

int main(int argc, char* argv[]) {
randomSeedTime();
randomInit();

#ifdef RELEASE
std::string logFilename = assetLocal("log.txt");


+ 4
- 2
src/util.cpp View File

@@ -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;


Loading…
Cancel
Save