diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-01-17 17:30:36 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-01-17 17:30:36 +0900 |
| commit | 9b41970134706f598ede204502bbd196eeedb26c (patch) | |
| tree | a57f0ef2c34f62e5c26e037870f8af666f8f0035 /src/SimpleRandomizer.cc | |
| parent | 0282899bfa41e49caebde19432b53570b14259c9 (diff) | |
Don't use std::random_device directly as suggested by document
See http://en.cppreference.com/w/cpp/numeric/random/random_device
Diffstat (limited to 'src/SimpleRandomizer.cc')
| -rw-r--r-- | src/SimpleRandomizer.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/SimpleRandomizer.cc b/src/SimpleRandomizer.cc index 11ce13d6..6a65d5f7 100644 --- a/src/SimpleRandomizer.cc +++ b/src/SimpleRandomizer.cc @@ -63,7 +63,11 @@ const std::unique_ptr<SimpleRandomizer>& SimpleRandomizer::getInstance() return randomizer_; } -SimpleRandomizer::SimpleRandomizer() +namespace { +std::random_device rd; +} // namespace + +SimpleRandomizer::SimpleRandomizer() : gen_(rd()) { #ifdef __MINGW32__ BOOL r = ::CryptAcquireContext(&provider_, 0, 0, PROV_RSA_FULL, @@ -120,12 +124,12 @@ void SimpleRandomizer::getRandomBytes(unsigned char* buf, size_t len) #endif // defined(HAVE_GETRANDOM_INTERFACE) auto ubuf = reinterpret_cast<result_type*>(buf); size_t q = len / sizeof(result_type); - auto gen = std::uniform_int_distribution<result_type>(); + auto dis = std::uniform_int_distribution<result_type>(); for (; q > 0; --q, ++ubuf) { - *ubuf = gen(dev_); + *ubuf = dis(gen_); } const size_t r = len % sizeof(result_type); - auto last = gen(dev_); + auto last = dis(gen_); memcpy(ubuf, &last, r); #endif // ! __MINGW32__ } |
