Package overit.geocall.util
Class RandomSequence
java.lang.Object
java.util.Random
overit.geocall.util.RandomSequence
- All Implemented Interfaces:
Serializable,RandomGenerator
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RandomSequenceGlobal instance to be shared across the application. -
Constructor Summary
ConstructorsConstructorDescriptionRandomSequence(double seed) Creates a new random number generator using adoubleseed that is trasformated inlongseed.RandomSequence(long seed) Creates a new random number generator using a singlelongseed.Creates a new random number generator using a seed. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidintnextHighInt(int n) It generates anIntegerbetween 0 and the value passed as parameter, with a probability distribution shifted to the greater numbers.
The distribution rule is quadratic polynomial.intnextInt(int n, int diff) Return a positiveIntegerand less than n, but different from diff.
Very useful for example if you have to extract two different numbers in a certain range.intnextLowInt(int n) It generates anIntegerbetween 0 and the value passed as parameter, with a probability distribution shifted to the lower numbers.
The distribution rule is quadratic polynomial.int[]permute(int[] ii) Mixes all the values within the array passed as input.int[]permute(int[] ii, int from, int length) Mixes a number of consecutive values within the array passed as input.Object[]Mixes all the values within the array passed as input.Object[]Mixes a number of consecutive values within the array passed as input.Mixes all the values within the array passed as input.Mixes a number of consecutive values within the array passed as input.Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs, next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.random.RandomGenerator
isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextLong, nextLong
-
Field Details
-
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 singlelongseed. The seed is the initial value of the internal state of the pseudorandom number generator which is maintained by methodRandom.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 adoubleseed that is trasformated inlongseed. The seed is the initial value of the internal state of the pseudorandom number generator which is maintained by methodRandom.next(int).- Parameters:
seed- the initial seed
-
RandomSequence
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 methodRandom.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 ofIntegerto 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 ofIntegerto 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
Mixes all the values within the array passed as input.- Parameters:
oo- array ofObjectto mix.- Returns:
- The mixed array.
-
permute
Mixes a number of consecutive values within the array passed as input.- Parameters:
oo- array ofObjectto 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
Mixes all the values within the array passed as input. -
permute
Mixes a number of consecutive values within the array passed as input. -
nextLowInt
public int nextLowInt(int n) It generates anIntegerbetween 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
Integerextracted.
-
nextHighInt
public int nextHighInt(int n) It generates anIntegerbetween 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
Integerextracted.
-
nextInt
public int nextInt(int n, int diff) Return a positiveIntegerand 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
Integerextracted.Random.next(int).
-
main
-