From: Jérôme Benoit Date: Wed, 7 Mar 2018 19:11:02 +0000 (+0100) Subject: TD1: Use thread optimized random number generator. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aee04a83cc5eecb50f85e71c4dbfc3ec2bf3cf69;p=TD_SR.git TD1: Use thread optimized random number generator. Signed-off-by: Jérôme Benoit --- diff --git a/TD1/exo3/Consommateur.java b/TD1/exo3/Consommateur.java index 5a54881..7aa8f30 100644 --- a/TD1/exo3/Consommateur.java +++ b/TD1/exo3/Consommateur.java @@ -1,3 +1,4 @@ +import java.util.concurrent.ThreadLocalRandom; public class Consommateur implements Runnable { @@ -16,7 +17,7 @@ public class Consommateur implements Runnable { val = (Integer)buffer.preleve(); System.out.println (Thread.currentThread().getName() + " a preleve " + val); try { - Thread.sleep((int)(Math.random()*1000)); + Thread.sleep(ThreadLocalRandom.current().nextInt(1001)); } catch (InterruptedException e) {} } diff --git a/TD1/exo3/Producteur.java b/TD1/exo3/Producteur.java index 10eab6d..d836af2 100644 --- a/TD1/exo3/Producteur.java +++ b/TD1/exo3/Producteur.java @@ -1,3 +1,4 @@ +import java.util.concurrent.ThreadLocalRandom; public class Producteur implements Runnable { @@ -17,7 +18,7 @@ public class Producteur implements Runnable { System.out.println (Thread.currentThread().getName() + " a depose " + val); val++; try { - Thread.sleep((int)(Math.random()*100)); + Thread.sleep(ThreadLocalRandom.current().nextInt(101)); } catch (InterruptedException e) {} }