A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'xbt_random' into 'master'
[simgrid.git]
/
examples
/
s4u
/
app-bittorrent
/
s4u-peer.cpp
diff --git
a/examples/s4u/app-bittorrent/s4u-peer.cpp
b/examples/s4u/app-bittorrent/s4u-peer.cpp
index
d3415ad
..
a5e59bb
100644
(file)
--- a/
examples/s4u/app-bittorrent/s4u-peer.cpp
+++ b/
examples/s4u/app-bittorrent/s4u-peer.cpp
@@
-446,8
+446,7
@@
int Peer::selectPieceToDownload(Connection* remote_peer)
xbt_assert(nb_interesting_pieces != 0);
// get a random interesting piece
xbt_assert(nb_interesting_pieces != 0);
// get a random interesting piece
- std::uniform_int_distribution<int> dist(0, nb_interesting_pieces - 1);
- int random_piece_index = dist(generator);
+ int random_piece_index = simgrid::xbt::random::uniform_int(0, nb_interesting_pieces - 1);
int current_index = 0;
for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (hasNotPiece(i) && remote_peer->hasPiece(i)) {
int current_index = 0;
for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (hasNotPiece(i) && remote_peer->hasPiece(i)) {
@@
-470,8
+469,7
@@
int Peer::selectPieceToDownload(Connection* remote_peer)
nb_interesting_pieces++;
xbt_assert(nb_interesting_pieces != 0);
// get a random interesting piece
nb_interesting_pieces++;
xbt_assert(nb_interesting_pieces != 0);
// get a random interesting piece
- std::uniform_int_distribution<int> dist(0, nb_interesting_pieces - 1);
- int random_piece_index = dist(generator);
+ int random_piece_index = simgrid::xbt::random::uniform_int(0, nb_interesting_pieces - 1);
int current_index = 0;
for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i)) {
int current_index = 0;
for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i)) {
@@
-504,8
+502,7
@@
int Peer::selectPieceToDownload(Connection* remote_peer)
// get a random rarest piece
int random_rarest_index = 0;
if (nb_min_pieces > 0) {
// get a random rarest piece
int random_rarest_index = 0;
if (nb_min_pieces > 0) {
- std::uniform_int_distribution<int> dist(0, nb_min_pieces - 1);
- random_rarest_index = dist(generator);
+ random_rarest_index = simgrid::xbt::random::uniform_int(0, nb_min_pieces - 1);
}
for (unsigned int i = 0; i < FILE_PIECES; i++)
if (pieces_count[i] == min && hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i)) {
}
for (unsigned int i = 0; i < FILE_PIECES; i++)
if (pieces_count[i] == min && hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i)) {
@@
-555,8
+552,7
@@
void Peer::updateChokedPeers()
do {
// We choose a random peer to unchoke.
std::unordered_map<int, Connection>::iterator chosen_peer_it = connected_peers.begin();
do {
// We choose a random peer to unchoke.
std::unordered_map<int, Connection>::iterator chosen_peer_it = connected_peers.begin();
- std::uniform_int_distribution<int> dist(0, connected_peers.size() - 1);
- std::advance(chosen_peer_it, dist(generator));
+ std::advance(chosen_peer_it, simgrid::xbt::random::uniform_int(0, connected_peers.size() - 1));
chosen_peer = &chosen_peer_it->second;
if (not chosen_peer->interested || not chosen_peer->choked_upload)
chosen_peer = nullptr;
chosen_peer = &chosen_peer_it->second;
if (not chosen_peer->interested || not chosen_peer->choked_upload)
chosen_peer = nullptr;