Class Randomizer


  • public final class Randomizer
    extends java.lang.Object
    This class is a wrapper around a random number generator. It is responsible for generating random objects (numbers, strings, etc.) and filling storages (arrays, collections, etc.) with random data.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T choose​(java.util.Collection<T> collection)
      Chooses a random item of the given collection.
      <T> T choose​(T[] array)
      Chooses a random item of the given array.
      void fill​(byte[] data)
      Fills the byte array with random data.
      void fill​(char[] data)
      Fills the char array with random data.
      void fill​(int[] data)
      Fills the int array with random data.
      void fill​(long[] data)
      Fills the long array with random data.
      void fill​(BitVector data)
      Fills the raw data storage with random data.
      static Randomizer get()
      Returns the randomizer instance.
      RandomGenerator getGenerator()
      Returns the current random number generator.
      int next()
      Generates the next random integer value.
      java.math.BigInteger nextBigIntegerField​(int width, boolean signed)
      Returns a random number of the given bit size (width).
      java.math.BigInteger nextBigIntegerRange​(java.math.BigInteger min, java.math.BigInteger max)
      Returns a random number from the given range.
      boolean nextBoolean()
      Generates the next random boolean.
      byte nextByte()
      Generates the next random byte.
      char nextChar()
      Generates the next random char.
      int nextInt()
      Generates the next random int.
      int nextIntField​(int width)
      Returns a random number of the given bit size (width).
      int nextIntField​(int lo, int hi)
      Returns a number with the randomized range of bits (field).
      int nextIntRange​(int min, int max)
      Returns a random number from the given range (inclusive).
      long nextLong()
      Generates the next random long.
      long nextLongField​(int width)
      Returns a random number of the given bit size (width).
      long nextLongField​(int lo, int hi)
      Returns a number with the randomized range of bits (field).
      long nextLongRange​(long min, long max)
      Returns a random number from the given range.
      <T> void permute​(T[] array)
      Permute items of the given array.
      void setGenerator​(RandomGenerator generator)
      Sets the current random number generator.
      void setSeed​(int seed)
      Sets the new seed of the random number generator.
      • Methods inherited from class java.lang.Object

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

      • get

        public static Randomizer get()
        Returns the randomizer instance.
        Returns:
        the randomizer instance.
      • getGenerator

        public RandomGenerator getGenerator()
        Returns the current random number generator.
        Returns:
        the random number generator.
      • setGenerator

        public void setGenerator​(RandomGenerator generator)
        Sets the current random number generator.
        Parameters:
        generator - the random number generator to be set.
      • setSeed

        public void setSeed​(int seed)
        Sets the new seed of the random number generator.
        Parameters:
        seed - the seed to be set.
      • next

        public int next()
        Generates the next random integer value.
        Returns:
        the next random integer number.
      • nextBoolean

        public boolean nextBoolean()
        Generates the next random boolean.
        Returns:
        A random boolean.
      • nextByte

        public byte nextByte()
        Generates the next random byte.
        Returns:
        A random byte.
      • nextChar

        public char nextChar()
        Generates the next random char.
        Returns:
        A random char.
      • nextInt

        public int nextInt()
        Generates the next random int.
        Returns:
        A random int.
      • nextLong

        public long nextLong()
        Generates the next random long.
        Returns:
        A random long.
      • nextIntRange

        public int nextIntRange​(int min,
                                int max)
        Returns a random number from the given range (inclusive).
        Parameters:
        min - the low bound of the range.
        max - the high bound of the range.
        Returns:
        a random number.
      • nextIntField

        public int nextIntField​(int width)
        Returns a random number of the given bit size (width).
        Parameters:
        width - the bit size.
        Returns:
        a random number.
      • nextIntField

        public int nextIntField​(int lo,
                                int hi)
        Returns a number with the randomized range of bits (field).
        Parameters:
        lo - the low bound of the field.
        hi - the high bound of the field.
        Returns:
        a random number.
      • nextLongRange

        public long nextLongRange​(long min,
                                  long max)
        Returns a random number from the given range.
        Parameters:
        min - the low bound of the range.
        max - the high bound of the range.
        Returns:
        a random number.
      • nextLongField

        public long nextLongField​(int width)
        Returns a random number of the given bit size (width).
        Parameters:
        width - the bit size.
        Returns:
        a random number.
      • nextLongField

        public long nextLongField​(int lo,
                                  int hi)
        Returns a number with the randomized range of bits (field).
        Parameters:
        lo - the low bound of the field.
        hi - the high bound of the field.
        Returns:
        a random number.
      • nextBigIntegerField

        public java.math.BigInteger nextBigIntegerField​(int width,
                                                        boolean signed)
        Returns a random number of the given bit size (width).
        Parameters:
        width - the bit size.
        signed - flag indicating that the result must be a signed value.
        Returns:
        a random number.
      • nextBigIntegerRange

        public java.math.BigInteger nextBigIntegerRange​(java.math.BigInteger min,
                                                        java.math.BigInteger max)
        Returns a random number from the given range.
        Parameters:
        min - the low bound of the range.
        max - the high bound of the range.
        Returns:
        a random number.
      • choose

        public <T> T choose​(T[] array)
        Chooses a random item of the given array.
        Type Parameters:
        T - array item type.
        Parameters:
        array - the array whose items are chosen.
        Returns:
        a random item of the array.
        Throws:
        java.lang.IllegalArgumentException - if array == null; if array is empty.
      • choose

        public <T> T choose​(java.util.Collection<T> collection)
        Chooses a random item of the given collection.
        Type Parameters:
        T - collection item type.
        Parameters:
        collection - the collection whose items are chosen.
        Returns:
        a random item of the collection.
        Throws:
        java.lang.IllegalArgumentException - if collection == null; if collection is empty.
      • permute

        public <T> void permute​(T[] array)
        Permute items of the given array.
        Type Parameters:
        T - array item type.
        Parameters:
        array - the array whose items to be permuted.
        Throws:
        java.lang.IllegalArgumentException - if array == null.
      • fill

        public void fill​(byte[] data)
        Fills the byte array with random data.
        Parameters:
        data - the array to be randomized.
      • fill

        public void fill​(char[] data)
        Fills the char array with random data.
        Parameters:
        data - the array to be randomized.
      • fill

        public void fill​(int[] data)
        Fills the int array with random data.
        Parameters:
        data - the array to be randomized.
      • fill

        public void fill​(long[] data)
        Fills the long array with random data.
        Parameters:
        data - the array to be randomized.
      • fill

        public void fill​(BitVector data)
        Fills the raw data storage with random data.
        Parameters:
        data - the raw data storage to be randomized.