Dropped new ThreadLocal in favor of ThreadLocalRandom.
This commit is contained in:
parent
5599581cea
commit
ccd7db72c4
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.util;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.<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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user