use random instead of rand()

This commit is contained in:
Arvid Norberg 2012-05-03 03:16:31 +00:00
parent 3a2916b578
commit bc34b13366
2 changed files with 5 additions and 4 deletions

View File

@ -193,7 +193,7 @@ int node_impl::bucket_size(int bucket)
void node_impl::new_write_key() void node_impl::new_write_key()
{ {
m_secret[1] = m_secret[0]; m_secret[1] = m_secret[0];
m_secret[0] = std::rand(); m_secret[0] = random();
} }
void node_impl::unreachable(udp::endpoint const& ep) void node_impl::unreachable(udp::endpoint const& ep)

View File

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/assert.hpp" #include "libtorrent/assert.hpp"
#include "libtorrent/broadcast_socket.hpp" // for is_local et.al #include "libtorrent/broadcast_socket.hpp" // for is_local et.al
#include "libtorrent/socket_io.hpp" // for hash_address #include "libtorrent/socket_io.hpp" // for hash_address
#include "libtorrent/random.hpp" // for random
namespace libtorrent { namespace dht namespace libtorrent { namespace dht
{ {
@ -137,7 +138,7 @@ node_id generate_id_impl(address const& ip, boost::uint32_t r)
node_id id = hasher((const char*)&seed, sizeof(seed)).final(); node_id id = hasher((const char*)&seed, sizeof(seed)).final();
for (int i = 4; i < 19; ++i) id[i] = rand(); for (int i = 4; i < 19; ++i) id[i] = random();
id[19] = r; id[19] = r;
@ -147,7 +148,7 @@ node_id generate_id_impl(address const& ip, boost::uint32_t r)
node_id generate_random_id() node_id generate_random_id()
{ {
char random[20]; char random[20];
for (int i = 0; i < 20; ++i) random[i] = rand(); for (int i = 0; i < 20; ++i) random[i] = libtorrent::random();
return hasher(random, 20).final(); return hasher(random, 20).final();
} }
@ -165,7 +166,7 @@ bool verify_id(node_id const& nid, address const& source_ip)
node_id generate_id(address const& ip) node_id generate_id(address const& ip)
{ {
return generate_id_impl(ip, rand()); return generate_id_impl(ip, random());
} }
} } // namespace libtorrent::dht } } // namespace libtorrent::dht