diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_8.2_Homunculus/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_8.2_Homunculus/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_8.2_Homunculus/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_8.2_Homunculus/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_9.2_ReturnOfTheQueenAnt/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_9.2_ReturnOfTheQueenAnt/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_9.2_ReturnOfTheQueenAnt/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_9.2_ReturnOfTheQueenAnt/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_C1_HarbingersOfWar/java/org/l2jmobius/util/Rnd.java b/L2J_Mobius_C1_HarbingersOfWar/java/org/l2jmobius/util/Rnd.java index d63ed4d471..896a9e7a09 100644 --- a/L2J_Mobius_C1_HarbingersOfWar/java/org/l2jmobius/util/Rnd.java +++ b/L2J_Mobius_C1_HarbingersOfWar/java/org/l2jmobius/util/Rnd.java @@ -1,51 +1,34 @@ /* * This file is part of the L2J Mobius project. * - * This program is free software; you can redistribute it and/or modify + * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program. If not, see . */ package org.l2jmobius.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -54,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -63,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -73,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -85,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -94,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -104,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -116,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -125,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -139,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -147,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -155,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } } diff --git a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/commons/util/Rnd.java b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/commons/util/Rnd.java index 7881f1bccf..af799d31f2 100644 --- a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/commons/util/Rnd.java +++ b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/commons/util/Rnd.java @@ -16,35 +16,19 @@ */ package org.l2jmobius.commons.util; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; /** * @author Mobius */ public class Rnd { - /** - * Thread-specific random number generator.
- * Each is seeded with the thread ID, so the sequence of random numbers are unique between threads. - */ - // Java 1.8 - // private static ThreadLocal RANDOM = new ThreadLocal() - // Java 10 - private static ThreadLocal RANDOM = new ThreadLocal<>() - { - @Override - protected Random initialValue() - { - return new Random(System.nanoTime() + Thread.currentThread().getId()); - } - }; - /** * @return a random boolean value. */ public static boolean nextBoolean() { - return RANDOM.get().nextBoolean(); + return ThreadLocalRandom.current().nextBoolean(); } /** @@ -53,7 +37,7 @@ public class Rnd */ public static void nextBytes(byte[] bytes) { - RANDOM.get().nextBytes(bytes); + ThreadLocalRandom.current().nextBytes(bytes); } /** @@ -62,7 +46,7 @@ public class Rnd */ public static int get(int bound) { - return (int) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextInt(bound); } /** @@ -72,11 +56,7 @@ public class Rnd */ public static int get(int origin, int bound) { - if (origin == bound) - { - return origin; - } - return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1); } /** @@ -84,7 +64,7 @@ public class Rnd */ public static int nextInt() { - return RANDOM.get().nextInt(); + return ThreadLocalRandom.current().nextInt(); } /** @@ -93,7 +73,7 @@ public class Rnd */ public static long get(long bound) { - return (long) (RANDOM.get().nextDouble() * bound); + return ThreadLocalRandom.current().nextLong(bound); } /** @@ -103,11 +83,7 @@ public class Rnd */ public static long get(long origin, long bound) { - if (origin == bound) - { - return origin; - } - return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L); } /** @@ -115,7 +91,7 @@ public class Rnd */ public static long nextLong() { - return RANDOM.get().nextLong(); + return ThreadLocalRandom.current().nextLong(); } /** @@ -124,7 +100,7 @@ public class Rnd */ public static double get(double bound) { - return RANDOM.get().nextDouble() * bound; + return ThreadLocalRandom.current().nextDouble(bound); } /** @@ -138,7 +114,7 @@ public class Rnd { return origin; } - return origin + (((bound - origin) + 1) * RANDOM.get().nextDouble()); + return ThreadLocalRandom.current().nextDouble(origin, bound == Double.MAX_VALUE ? bound : bound + 0.000000000000001d); } /** @@ -146,7 +122,7 @@ public class Rnd */ public static double nextDouble() { - return RANDOM.get().nextDouble(); + return ThreadLocalRandom.current().nextDouble(); } /** @@ -154,6 +130,6 @@ public class Rnd */ public static double nextGaussian() { - return RANDOM.get().nextGaussian(); + return ThreadLocalRandom.current().nextGaussian(); } }