Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Removing RngStream
[simgrid.git] / examples / deprecated / java / app / bittorrent / Peer.java
index 6491bd6..17ba118 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2006-2019. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2006-2019. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -10,20 +9,20 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map.Entry;
+import java.util.Random;
 
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.Comm;
 import org.simgrid.msg.Host;
 import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
-import org.simgrid.msg.RngStream;
 import org.simgrid.msg.MsgException;
 
 public class Peer extends Process {
+  Random rand = new Random();
   protected int round = 0;
   protected double beginReceiveTime;
   protected double deadline;
-  protected static RngStream stream = new RngStream();
   protected int id;
   protected String mailbox;
   protected String mailboxTracker;
@@ -49,11 +48,8 @@ public class Peer extends Process {
     if (args.length != 3 && args.length != 2) {
       Msg.info("Wrong number of arguments");
     }
-    if (args.length == 3) {
-      init(Integer.parseInt(args[0]),true);
-    } else {
-      init(Integer.parseInt(args[0]),false);
-    }
+    init(Integer.parseInt(args[0]), (args.length == 3));
+     
     //Retrieve the deadline
     deadline = Double.parseDouble(args[1]);
     if (deadline < 0) {
@@ -388,7 +384,7 @@ public class Peer extends Process {
 
     //TODO: trivial min algorithm when pieces >= 3
     do {
-      currentPiece = stream.randInt(0,Common.FILE_PIECES - 1);
+      currentPiece = rand.nextInt(Common.FILE_PIECES);
     } while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece)));
 
     currentPieces.add(currentPiece);
@@ -428,7 +424,7 @@ public class Peer extends Process {
         int j = 0;
         do {
           int i = 0;
-          int idChosen = stream.randInt(0,peers.size() - 1);
+          int idChosen = rand.nextInt(peers.size());
           for (Connection connection : peers.values()) {
             if (i == idChosen) {
               peerChoosed = connection;