Class AssertingRandom
- java.lang.Object
-
- java.util.Random
-
- com.carrotsearch.randomizedtesting.AssertingRandom
-
- All Implemented Interfaces:
java.io.Serializable
public final class AssertingRandom extends java.util.Random
A random with a delegate, preventingRandom.setSeed(long)
and locked to be used by a single thread.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StackTraceElement[]
allocationStack
private static boolean
assertionsEnabled
Enable paranoid mode when assertions are enabled.private java.util.Random
delegate
private java.lang.String
ownerName
private java.lang.ref.WeakReference<java.lang.Thread>
ownerRef
private boolean
valid
Track out-of-context use of thisRandom
instance.
-
Constructor Summary
Constructors Constructor Description AssertingRandom(java.lang.Thread owner, java.util.Random delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkValid()
protected java.lang.Object
clone()
void
destroy()
This object will no longer be usable after this method is called.boolean
equals(java.lang.Object obj)
int
hashCode()
static boolean
isVerifying()
protected int
next(int bits)
boolean
nextBoolean()
void
nextBytes(byte[] bytes)
double
nextDouble()
float
nextFloat()
double
nextGaussian()
int
nextInt()
int
nextInt(int n)
long
nextLong()
(package private) static java.lang.RuntimeException
noSetSeed()
void
setSeed(long seed)
java.lang.String
toString()
-
-
-
Field Detail
-
delegate
private final java.util.Random delegate
-
ownerRef
private final java.lang.ref.WeakReference<java.lang.Thread> ownerRef
-
ownerName
private final java.lang.String ownerName
-
allocationStack
private final java.lang.StackTraceElement[] allocationStack
-
valid
private volatile boolean valid
Track out-of-context use of thisRandom
instance. This introduces memory barriers and scheduling side-effects but there's no other way to do it in any other way and sharing randoms across threads or test cases is very bad and worth tracking.
-
assertionsEnabled
private static final boolean assertionsEnabled
Enable paranoid mode when assertions are enabled.
-
-
Method Detail
-
next
protected int next(int bits)
- Overrides:
next
in classjava.util.Random
-
nextBoolean
public boolean nextBoolean()
- Overrides:
nextBoolean
in classjava.util.Random
-
nextBytes
public void nextBytes(byte[] bytes)
- Overrides:
nextBytes
in classjava.util.Random
-
nextDouble
public double nextDouble()
- Overrides:
nextDouble
in classjava.util.Random
-
nextFloat
public float nextFloat()
- Overrides:
nextFloat
in classjava.util.Random
-
nextGaussian
public double nextGaussian()
- Overrides:
nextGaussian
in classjava.util.Random
-
nextInt
public int nextInt()
- Overrides:
nextInt
in classjava.util.Random
-
nextInt
public int nextInt(int n)
- Overrides:
nextInt
in classjava.util.Random
-
nextLong
public long nextLong()
- Overrides:
nextLong
in classjava.util.Random
-
setSeed
public void setSeed(long seed)
- Overrides:
setSeed
in classjava.util.Random
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
destroy
public void destroy()
This object will no longer be usable after this method is called.
-
checkValid
private final void checkValid()
-
clone
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
isVerifying
public static boolean isVerifying()
- Returns:
- Return
true
if this class is verifying sharing and lifecycle assertions. - See Also:
- "https://github.com/randomizedtesting/randomizedtesting/issues/234"
-
noSetSeed
static java.lang.RuntimeException noSetSeed()
-
-