Class KRandom

java.lang.Object
java.util.Random
io.github.krandom.KRandom
All Implemented Interfaces:
Serializable, RandomGenerator

public class KRandom extends Random
Extension of Random that is able to generate random Java objects.
See Also:
  • Constructor Details

    • KRandom

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

      public KRandom(KRandomParameters kRandomParameters)
      Create a new KRandom instance.
      Parameters:
      kRandomParameters - 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> 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