Class EasyRandom

java.lang.Object
java.util.Random
org.jeasy.random.EasyRandom
All Implemented Interfaces:
Serializable, java.util.random.RandomGenerator

public class EasyRandom extends Random
Extension of Random that is able to generate random Java objects.
Author:
Mahmoud Ben Hassine ([email protected])
See Also:
  • Constructor Details

    • EasyRandom

      public EasyRandom()
      Create a new EasyRandom instance with default parameters.
    • EasyRandom

      public EasyRandom(EasyRandomParameters easyRandomParameters)
      Create a new EasyRandom instance.
      Parameters:
      easyRandomParameters - randomization parameters
  • Method Details

    • nextObject

      public <T> T nextObject(Class<T> type)
      Generate a random instance of the given type.
      Type Parameters:
      T - the actual type of the target object
      Parameters:
      type - the type for which an instance will be generated
      Returns:
      a random instance of the given type
      Throws:
      ObjectCreationException - when unable to create a new instance of the given type
    • objects

      public <T> java.util.stream.Stream<T> objects(Class<T> type, int streamSize)
      Generate a stream of random instances of the given type.
      Type Parameters:
      T - the actual type of the target objects
      Parameters:
      type - the type for which instances will be generated
      streamSize - the number of instances to generate
      Returns:
      a stream of random instances of the given type
      Throws:
      ObjectCreationException - when unable to create a new instance of the given type