TD1: Use a thread optimized random number generator.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 6 Mar 2018 22:38:54 +0000 (23:38 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 6 Mar 2018 22:38:54 +0000 (23:38 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TD1/exo2/ThreadJob.java

index dae83baa750588b57e0523d1a0797e56241951e9..32a7365f2a66de51747fba74a6eb18f282641a65 100644 (file)
@@ -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);
             }