Class RandomSequence

java.lang.Object
java.util.Random
overit.geocall.util.RandomSequence
All Implemented Interfaces:
Serializable, RandomGenerator

public class RandomSequence extends Random
Auxiliary class to extend the functionality of the class Random. In particular, adds methods to permute elements in an array and to extract an element by increasing the probability that it is a great or a low value.
See Also:
  • Field Details

    • GLOBAL_INSTANCE

      public static final RandomSequence GLOBAL_INSTANCE
      Global instance to be shared across the application. This helps to improve the efficiency and the randomness of the generated numbers
  • Constructor Details

    • RandomSequence

      public RandomSequence()
    • RandomSequence

      public RandomSequence(long seed)
      Creates a new random number generator using a single long seed. The seed is the initial value of the internal state of the pseudorandom number generator which is maintained by method Random.next(int).

      The invocation new RandomSequence(seed) is equivalent to:

       
       RandomSequence rs = new RandomSequence();
       rs.setSeed(seed);
      Parameters:
      seed - the initial seed
      See Also:
    • RandomSequence

      public RandomSequence(double seed)
      Creates a new random number generator using a double seed that is trasformated in long seed. The seed is the initial value of the internal state of the pseudorandom number generator which is maintained by method Random.next(int).
      Parameters:
      seed - the initial seed
    • RandomSequence

      public RandomSequence(String s)
      Creates a new random number generator using a seed. The seed is extracted from the string passed in input. The seed is the initial value of the internal state of the pseudorandom number generator which is maintained by method Random.next(int).
      Parameters:
      s - The string to interpret to create the seed.
  • Method Details

    • permute

      public int[] permute(int[] ii)
      Mixes all the values within the array passed as input.
      Parameters:
      ii - array of Integer to mix.
      Returns:
      The mixed array.
    • permute

      public int[] permute(int[] ii, int from, int length)
      Mixes a number of consecutive values within the array passed as input.
      Parameters:
      ii - array of Integer to mix.
      from - Start index from which to start mixing. The index is inclusive.
      length - Lenght of the interval to be shuffled.
      Returns:
      The mixed array.
    • permute

      public Object[] permute(Object[] oo)
      Mixes all the values within the array passed as input.
      Parameters:
      oo - array of Object to mix.
      Returns:
      The mixed array.
    • permute

      public Object[] permute(Object[] oo, int from, int length)
      Mixes a number of consecutive values within the array passed as input.
      Parameters:
      oo - array of Object to mix.
      from - Start index from which to start mixing. The index is inclusive.
      length - Lenght of the interval to be shuffled.
      Returns:
      The mixed array.
    • permute

      public ArrayList permute(ArrayList al)
      Mixes all the values within the array passed as input.
      Parameters:
      al - ArrayList of Object to mix.
      Returns:
      The mixed array.
    • permute

      public ArrayList permute(ArrayList al, int from, int length)
      Mixes a number of consecutive values within the array passed as input.
      Parameters:
      al - ArrayList of Object to mix.
      from - Start index from which to start mixing. The index is inclusive.
      length - Lenght of the interval to be shuffled.
      Returns:
      The mixed array.
    • nextLowInt

      public int nextLowInt(int n)
      It generates an Integer between 0 and the value passed as parameter, with a probability distribution shifted to the lower numbers.
      The distribution rule is quadratic polynomial.
      Parameters:
      n - The maximum value it can take.
      Returns:
      The Integer extracted.
    • nextHighInt

      public int nextHighInt(int n)
      It generates an Integer between 0 and the value passed as parameter, with a probability distribution shifted to the greater numbers.
      The distribution rule is quadratic polynomial.
      Parameters:
      n - The maximum value it can take.
      Returns:
      The Integer extracted.
    • nextInt

      public int nextInt(int n, int diff)
      Return a positive Integer and less than n, but different from diff.
      Very useful for example if you have to extract two different numbers in a certain range.
      Parameters:
      n - Maximum limit of the value that can be extracted. This value is not included.
      diff - The return value must be different from this value
      Returns:
      The Integer extracted. Random.next(int).
    • main

      public static void main(String[] args)