Dropped new ThreadLocal in favor of ThreadLocalRandom.

This commit is contained in:
MobiusDevelopment
2021-10-15 21:13:59 +00:00
parent 5599581cea
commit ccd7db72c4
24 changed files with 319 additions and 896 deletions

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -1,51 +1,34 @@
/* /*
* This file is part of the L2J Mobius project. * 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 * 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. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* GNU General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package org.l2jmobius.util; package org.l2jmobius.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -85,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -116,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -155,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }

View File

@@ -16,35 +16,19 @@
*/ */
package org.l2jmobius.commons.util; package org.l2jmobius.commons.util;
import java.util.Random; import java.util.concurrent.ThreadLocalRandom;
/** /**
* @author Mobius * @author Mobius
*/ */
public class Rnd public class Rnd
{ {
/**
* Thread-specific random number generator.<br>
* Each is seeded with the thread ID, so the sequence of random numbers are unique between threads.
*/
// Java 1.8
// private static ThreadLocal<Random> RANDOM = new ThreadLocal<Random>()
// Java 10
private static ThreadLocal<Random> RANDOM = new ThreadLocal<>()
{
@Override
protected Random initialValue()
{
return new Random(System.nanoTime() + Thread.currentThread().getId());
}
};
/** /**
* @return a random boolean value. * @return a random boolean value.
*/ */
public static boolean nextBoolean() 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) 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) 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) public static int get(int origin, int bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextInt(origin, bound == Integer.MAX_VALUE ? bound : bound + 1);
{
return origin;
}
return origin + (int) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -84,7 +64,7 @@ public class Rnd
*/ */
public static int nextInt() 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) 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) public static long get(long origin, long bound)
{ {
if (origin == bound) return ThreadLocalRandom.current().nextLong(origin, bound == Long.MAX_VALUE ? bound : bound + 1L);
{
return origin;
}
return origin + (long) (((bound - origin) + 1) * RANDOM.get().nextDouble());
} }
/** /**
@@ -115,7 +91,7 @@ public class Rnd
*/ */
public static long nextLong() 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) 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;
} }
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() public static double nextDouble()
{ {
return RANDOM.get().nextDouble(); return ThreadLocalRandom.current().nextDouble();
} }
/** /**
@@ -154,6 +130,6 @@ public class Rnd
*/ */
public static double nextGaussian() public static double nextGaussian()
{ {
return RANDOM.get().nextGaussian(); return ThreadLocalRandom.current().nextGaussian();
} }
} }