Class RandomGenerator
- java.lang.Object
-
- com.datumbox.framework.common.utilities.RandomGenerator
-
public class RandomGenerator extends Object
The RandomGenerator generates Random objects that can be read and modified by the same thread. The class can be configured with a globalSeed that is used to initialize all the generated Random objects.- Author:
- Vasilis Vryniotis
-
-
Constructor Summary
Constructors Constructor Description RandomGenerator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static LonggetGlobalSeed()Getter for the global seed.static RandomgetThreadLocalRandom()Returns a Random object which is stored as ThreadLocal variable and as a result each Thread has an independent copy of this variable.static RandomgetThreadLocalRandomUnseeded()Returns a Random object which is local for the thread but unseeded.static voidsetGlobalSeed(Long globalSeed)Setter for the global seed.
-
-
-
Method Detail
-
getGlobalSeed
public static Long getGlobalSeed()
Getter for the global seed. The global seed affects the initial seeding of all the Random objects that are generated by this class.- Returns:
-
setGlobalSeed
public static void setGlobalSeed(Long globalSeed)
Setter for the global seed. The global seed affects the initial seeding of all the Random objects that are generated by this class. Changing the global seed does not affect the Random objects that have already been generated. If you wish to change the seed of an already initialized Random object use the setSeed() method of that object.- Parameters:
globalSeed-
-
getThreadLocalRandom
public static Random getThreadLocalRandom()
Returns a Random object which is stored as ThreadLocal variable and as a result each Thread has an independent copy of this variable. When the Random objects are initialized, they seeded with the global seed (if not null).- Returns:
-
getThreadLocalRandomUnseeded
public static Random getThreadLocalRandomUnseeded()
Returns a Random object which is local for the thread but unseeded.- Returns:
-
-