Class Random


  • public final class Random
    extends java.lang.Object
    The Random class provides facilities to generate random data (Data and Variable objects). The current implementation uses the Randomizer class to generate random values. It is possible to customize the behavior by providing a custom generation engine (a custom implementation of the Random.Engine interface).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Random.CompositeEngine
      The Random.CompositeEngine class is a reusable implementation of the Engine interface.
      static interface  Random.Engine
      The Random.Engine interface is a common interface to be implemented by all generation engines.
      static interface  Random.Initializer
      The Initializer interface is to be implemented by objects that are responsible for initializing some specific generation engine.
      static interface  Random.TypedGenerator
      The TypedGenerator interface is a common interface for objects that are responsible for generating data of some specific type.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Variable assignValue​(Variable variable)
      Assigns a random value to the specified variable.
      static Random.Engine getEngine()
      Returns an instance of the random data generation engine.
      static Data newValue​(DataType type)
      Creates a data object of the specified type initialized with a random value.
      static Variable newVariable​(java.lang.String name, DataType type)
      Creates a variable of the specified type initialized with a random value.
      static void setEngine​(Random.Engine value)
      Sets the random data generation engine to be used to generate data.
      static void setSeed​(int seed)
      Sets a new seed of the random data generation engine.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getEngine

        public static Random.Engine getEngine()
        Returns an instance of the random data generation engine. If the method is called for the first time and no custom engine has been set up by setEngine method, a default engine is created and returned.
        Returns:
        Random data generation engine being used.
      • setEngine

        public static void setEngine​(Random.Engine value)
        Sets the random data generation engine to be used to generate data.
        Parameters:
        value - Random data generation engine.
        Throws:
        java.lang.IllegalArgumentException - if the parameter equals null.
      • setSeed

        public static void setSeed​(int seed)
        Sets a new seed of the random data generation engine.
        Parameters:
        seed - The seed to be set.
      • newValue

        public static Data newValue​(DataType type)
        Creates a data object of the specified type initialized with a random value.
        Parameters:
        type - Data type.
        Returns:
        Random data.
        Throws:
        java.lang.IllegalArgumentException - if the parameter equals null.
        java.lang.UnsupportedOperationException - if random data generation is not supported by the given data type.
      • newVariable

        public static Variable newVariable​(java.lang.String name,
                                           DataType type)
        Creates a variable of the specified type initialized with a random value.
        Parameters:
        name - Variable name.
        type - Variable data type.
        Returns:
        Variable initialized with a random value.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters equals null.
        java.lang.UnsupportedOperationException - if random data generation is not supported by the given data type.
      • assignValue

        public static Variable assignValue​(Variable variable)
        Assigns a random value to the specified variable.
        Parameters:
        variable - Variable to be assigned.
        Returns:
        Variable with a value assigned (same instance).
        Throws:
        java.lang.UnsupportedOperationException - if the parameter equals null; if random data generation is not supported by the given data type.