From b0f9b27c32d4599150eec0ce102695b328d87e7c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 6 Mar 2018 23:38:54 +0100 Subject: [PATCH] TD1: Use a 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/exo2/ThreadJob.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/TD1/exo2/ThreadJob.java b/TD1/exo2/ThreadJob.java index dae83ba..32a7365 100644 --- a/TD1/exo2/ThreadJob.java +++ b/TD1/exo2/ThreadJob.java @@ -1,4 +1,4 @@ -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; public class ThreadJob implements Runnable { @@ -12,8 +12,7 @@ public class ThreadJob implements Runnable { public void run() { for (int j = 0; j < 10; j++) { - Random rand = new Random(); - int sleep_time = rand.nextInt(201); + int sleep_time = ThreadLocalRandom.current().nextInt(201); try { Thread.sleep(sleep_time); } -- 2.34.1