diff --git a/c++/perspective/src/generator.cpp b/c++/perspective/src/generator.cpp index d80baec..48bc1f7 100644 --- a/c++/perspective/src/generator.cpp +++ b/c++/perspective/src/generator.cpp @@ -29,8 +29,9 @@ Real Generator::random(const ULongIntVector2 &coord, int index) const { ULongInt seed = random(random(coord.x) ^ seeds_x()[index]); seed = random(seed ^ random(coord.y) ^ seeds_y()[index]); - seed = random(seed ^ random(coord.x) ^ random(coord.y)); - return Real(seed)/Real(ULLONG_MAX)*Real(2) - Real(1); + const ULongInt x = seed = random(seed ^ random(coord.x) ^ random(coord.y)); + const ULongInt y = seed = random(seed); + return random_to_normal(x, y); } Vector4 @@ -93,6 +94,9 @@ Generator::generate(const ULongIntVector2 &coord, bool shrink_cache) const { + generate(ULongIntVector2(coord.x, coord.y + level)) )*0.25; } } + + for(int j = 0; j < 4; ++j) + value[j] = mirror_repeat(value[j]); } i->second.in_use = false; diff --git a/c++/perspective/src/generator.h b/c++/perspective/src/generator.h index 3d44432..92cfc77 100644 --- a/c++/perspective/src/generator.h +++ b/c++/perspective/src/generator.h @@ -43,8 +43,18 @@ public: ++x; return x; } + static inline Real random_to_real(ULongInt x) { return Real(x)/Real(ULLONG_MAX); } + static inline Real random_to_normal(ULongInt x, ULongInt y) + { return sqrt(-2*log(random_to_real(x))) * sin(2*M_PI*random_to_real(y)); } + + static inline Real mirror_repeat(Real x) { + x *= 0.5; + x -= floor(x); + x *= 2; + return x > 1 ? 2 - x : x; + } private: const ULongInt one;