diff --git a/src/random.cpp b/src/random.cpp index 096bda906..f8698441c 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -30,7 +30,9 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include "libtorrent/config.hpp" #include "libtorrent/random.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { @@ -38,17 +40,25 @@ namespace libtorrent namespace { boost::uint32_t x = 123456789; +#ifdef TORRENT_USE_ASSERTS + bool seeded = false; +#endif } void random_seed(boost::uint32_t v) { x = v; +#ifdef TORRENT_USE_ASSERTS + seeded = true; +#endif } // this is an xorshift random number generator // see: http://en.wikipedia.org/wiki/Xorshift boost::uint32_t random() { + TORRENT_ASSERT(seeded); + static boost::uint32_t y = 362436069; static boost::uint32_t z = 521288629; static boost::uint32_t w = 88675123; diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 9ca783a62..cf26e2bdd 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -434,6 +434,8 @@ bool get_item_cb(dht::item& i) // TODO: 3 test obfuscated_get_peers int test_main() { + random_seed(time_now_hires().time_since_epoch().count()); + dht_settings sett; sett.max_torrents = 4; sett.max_dht_items = 4; diff --git a/test/test_pe_crypto.cpp b/test/test_pe_crypto.cpp index 8770e0198..9cbd635de 100644 --- a/test/test_pe_crypto.cpp +++ b/test/test_pe_crypto.cpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hasher.hpp" #include "libtorrent/pe_crypto.hpp" #include "libtorrent/session.hpp" +#include "libtorrent/random.hpp" #include "setup_transfer.hpp" #include "test.hpp" @@ -181,6 +182,8 @@ int test_main() const int repcount = 128; #endif + random_seed(time_now_hires().time_since_epoch().count()); + for (int rep = 0; rep < repcount; ++rep) { dh_key_exchange DH1, DH2; diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index 4f05079da..f64e87c9d 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -34,6 +34,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/torrent_peer.hpp" #include "libtorrent/bitfield.hpp" #include "libtorrent/performance_counters.hpp" +#include "libtorrent/random.hpp" + #include #include #include @@ -269,6 +271,9 @@ int test_pick(boost::shared_ptr const& p, int options = piece_pick int test_main() { + random_seed(time_now_hires().time_since_epoch().count()); + + tcp::endpoint endp; piece_picker::downloading_piece st; #if TORRENT_USE_ASSERTS tmp0.in_use = true; diff --git a/test/test_policy.cpp b/test/test_policy.cpp index 39d42dc32..bccc697fe 100644 --- a/test/test_policy.cpp +++ b/test/test_policy.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/ip_voter.hpp" #include "libtorrent/ip_filter.hpp" #include "libtorrent/peer_info.hpp" +#include "libtorrent/random.hpp" #include "test.hpp" #include "setup_transfer.hpp" @@ -132,6 +133,8 @@ private: int test_main() { + random_seed(time_now_hires().time_since_epoch().count()); + torrent_peer_allocator allocator; external_ip ext_ip;