diff --git a/lemon/random.h b/lemon/random.h --- a/lemon/random.h +++ b/lemon/random.h @@ -77,7 +77,7 @@ #include #include #else -#include +#include #endif ///\ingroup misc @@ -344,56 +344,46 @@ } }; - template = 0)> + template struct ShiftMultiplier { static const Result multiplier() { Result res = ShiftMultiplier::multiplier(); res *= res; - if ((exp & 1) == 1) res *= static_cast(2.0); - return res; - } - }; - - template - struct ShiftMultiplier { - static const Result multiplier() { - Result res = ShiftMultiplier::multiplier(); - res *= res; if ((exp & 1) == 1) res *= static_cast(0.5); return res; } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { return static_cast(1.0); } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { return static_cast(1.0/1048576.0); } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { - return static_cast(1.0/424967296.0); + return static_cast(1.0/4294967296.0); } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { return static_cast(1.0/9007199254740992.0); } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { return static_cast(1.0/18446744073709551616.0); } @@ -413,7 +403,7 @@ static const int bits = std::numeric_limits::digits; static Result convert(RandomCore& rnd) { - return Shifting:: + return Shifting:: shift(static_cast(rnd() >> (bits - rest))); } }; @@ -423,7 +413,7 @@ static const int bits = std::numeric_limits::digits; static Result convert(RandomCore& rnd) { - return Shifting:: + return Shifting:: shift(static_cast(rnd())) + RealConversion:: convert(rnd); @@ -613,7 +603,7 @@ /// By default, this function calls the \c seedFromFile() member /// function with the /dev/urandom file. If it does not success, /// it uses the \c seedFromTime(). - /// \return Currently always true. + /// \return Currently always \c true. bool seed() { #ifndef WIN32 if (seedFromFile("/dev/urandom", 0)) return true; @@ -634,7 +624,7 @@ /// entropy). /// \param file The source file /// \param offset The offset, from the file read. - /// \return True when the seeding successes. + /// \return \c true when the seeding successes. #ifndef WIN32 bool seedFromFile(const std::string& file = "/dev/urandom", int offset = 0) #else @@ -655,23 +645,21 @@ /// Seding from process id and time. This function uses the /// current process id and the current time for initialize the /// random sequence. - /// \return Currently always true. + /// \return Currently always \c true. bool seedFromTime() { #ifndef WIN32 timeval tv; gettimeofday(&tv, 0); seed(getpid() + tv.tv_sec + tv.tv_usec); #else - FILETIME time; - GetSystemTimeAsFileTime(&time); - seed(GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime); + seed(bits::getWinRndSeed()); #endif return true; } /// @} - ///\name Uniform distributions + ///\name Uniform Distributions /// /// @{ @@ -774,7 +762,7 @@ /// @} - ///\name Non-uniform distributions + ///\name Non-uniform Distributions /// ///@{ @@ -950,7 +938,7 @@ ///@} - ///\name Two dimensional distributions + ///\name Two Dimensional Distributions /// ///@{