Fix createPackets

This commit is contained in:
Quentin Legot 2023-03-17 10:29:36 +01:00
parent b5691cb6d0
commit cb0ad20d89
2 changed files with 7 additions and 6 deletions

View File

@ -57,17 +57,18 @@ public class AccessPoint {
private void updateBandwidth(int ticks) { private void updateBandwidth(int ticks) {
int n = 200; int n = 200;
int timeInterval = 50 + new Random().nextInt(50); Random random = new Random();
int timeInterval = 50 + random.nextInt(51);
for(User user : users) { for(User user : users) {
// On regénère le tableau de débits toutes les 50 ms // On régénère le tableau de débits toutes les 50 ms
if(ticks % 50 == 0){ if(ticks % 50 == 0){
user.generateBandwidth(); user.generateBandwidth();
} }
// On regénère les sources toutes les 50-100 ms // On régénère les sources toutes les 50-100 ms
if(ticks % timeInterval == 0){ if(ticks % timeInterval == 0){
n = user.createPackets(n); n = user.createPackets(n);
timeInterval = 50 + new Random().nextInt(51); timeInterval = 50 + random.nextInt(51);
} }
} }
} }

View File

@ -35,11 +35,11 @@ public class User {
public int createPackets(int m) { public int createPackets(int m) {
Random random = new Random(); Random random = new Random();
int mbis = (int) random.nextDouble() * (2 * m); int mbis = random.nextInt(2 * m);
int nbPacketsToSend = mbis / Packets.packetSize; int nbPacketsToSend = mbis / Packets.packetSize;
this.leftForNextSource = mbis % Packets.packetSize; this.leftForNextSource = mbis % Packets.packetSize;
for(int i = 0; i < nbPacketsToSend; i++){ for(int i = 0; i < nbPacketsToSend; i++){
this.packetsToSend.add(new Packets(i, i, i)); // Voir pour les valeurs du contructeur Packets this.packetsToSend.add(new Packets(i, i, i)); // Voir pour les valeurs du constructeur Packets
} }
return mbis; return mbis;
} }