Browse Source

Use boost counterparts. Apparently std::random and boost::random are not

reliably interoperable.
cl-refactor
Gav Wood 10 years ago
parent
commit
5904badec7
  1. 6
      libdevcore/CommonData.cpp
  2. 3
      libdevcore/FixedHash.h
  3. 3
      libdevcore/vector_ref.h
  4. 3
      libethash-cl/ethash_cl_miner.cpp

6
libdevcore/CommonData.cpp

@ -20,7 +20,7 @@
*/ */
#include "CommonData.h" #include "CommonData.h"
#include <boost/random/uniform_int_distribution.hpp>
#include "Exceptions.h" #include "Exceptions.h"
#include "Log.h" #include "Log.h"
@ -58,9 +58,9 @@ std::string dev::escaped(std::string const& _s, bool _all)
std::string dev::randomWord() std::string dev::randomWord()
{ {
static std::mt19937_64 s_eng(0); static std::mt19937_64 s_eng(0);
std::string ret(std::uniform_int_distribution<int>(1, 5)(s_eng), ' '); std::string ret(boost::random::uniform_int_distribution<int>(1, 5)(s_eng), ' ');
char const n[] = "qwertyuiop";//asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890"; char const n[] = "qwertyuiop";//asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
std::uniform_int_distribution<int> d(0, sizeof(n) - 2); boost::random::uniform_int_distribution<int> d(0, sizeof(n) - 2);
for (char& c: ret) for (char& c: ret)
c = n[d(s_eng)]; c = n[d(s_eng)];
return ret; return ret;

3
libdevcore/FixedHash.h

@ -27,6 +27,7 @@
#include <cstdint> #include <cstdint>
#include <algorithm> #include <algorithm>
#include <boost/random/random_device.hpp> #include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include "CommonData.h" #include "CommonData.h"
namespace dev namespace dev
@ -154,7 +155,7 @@ public:
{ {
FixedHash ret; FixedHash ret;
for (auto& i: ret.m_data) for (auto& i: ret.m_data)
i = (uint8_t)std::uniform_int_distribution<uint16_t>(0, 255)(_eng); i = (uint8_t)boost::random::uniform_int_distribution<uint16_t>(0, 255)(_eng);
return ret; return ret;
} }

3
libdevcore/vector_ref.h

@ -7,6 +7,7 @@
#include <string> #include <string>
#include <random> #include <random>
#include <boost/random/random_device.hpp> #include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>
namespace dev namespace dev
{ {
@ -76,7 +77,7 @@ public:
{ {
uint8_t* e = (uint8_t*)end(); uint8_t* e = (uint8_t*)end();
for (uint8_t* i = (uint8_t*)begin(); i != e; ++i) for (uint8_t* i = (uint8_t*)begin(); i != e; ++i)
*i = (uint8_t)std::uniform_int_distribution<uint16_t>(0, 255)(_eng); *i = (uint8_t)boost::random::uniform_int_distribution<uint16_t>(0, 255)(_eng);
} }
/// @returns a random valued object. /// @returns a random valued object.
void randomize() { randomize(s_vectorRefEngine); } void randomize() { randomize(s_vectorRefEngine); }

3
libethash-cl/ethash_cl_miner.cpp

@ -32,6 +32,7 @@
#include <vector> #include <vector>
#include <random> #include <random>
#include <boost/random/random_device.hpp> #include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <libethash/util.h> #include <libethash/util.h>
#include <libethash/ethash.h> #include <libethash/ethash.h>
#include <libethash/internal.h> #include <libethash/internal.h>
@ -472,7 +473,7 @@ void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook
unsigned buf = 0; unsigned buf = 0;
boost::random_device engine; boost::random_device engine;
uint64_t start_nonce = uniform_int_distribution<uint64_t>()(engine); uint64_t start_nonce = boost::random::uniform_int_distribution<uint64_t>()(engine);
for (;; start_nonce += m_globalWorkSize) for (;; start_nonce += m_globalWorkSize)
{ {
auto t = chrono::high_resolution_clock::now(); auto t = chrono::high_resolution_clock::now();

Loading…
Cancel
Save