From aee04a83cc5eecb50f85e71c4dbfc3ec2bf3cf69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 7 Mar 2018 20:11:02 +0100 Subject: [PATCH] TD1: Use thread optimized random number generator. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TD1/exo3/Consommateur.java | 3 ++- TD1/exo3/Producteur.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) 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) {} } -- 2.34.1