Class RandomWithDuplicates
java.lang.Object
edu.gvsu.kurmasz.warszawa.listgen.IntegerListGenerator
edu.gvsu.kurmasz.warszawa.listgen.RandomWithDuplicates
- Direct Known Subclasses:
RandomWithoutDuplicates
public class RandomWithDuplicates extends IntegerListGenerator
Generate lists of random integers within a specified range. Note:
generateLongArray
is not yet implemented for values outside of an
integer range.- Author:
- Zachary Kurmas
-
Constructor Summary
Constructors Constructor Description RandomWithDuplicates()
Default constructor.RandomWithDuplicates(java.util.Random rin)
Constructor allowing user to specify whichjava.util.Random
object to use. -
Method Summary
Modifier and Type Method Description int[]
generateIntArray(int min, int max, int amount)
Generate an array ofamount
random integers containing the values betweenmin
andmax
(inclusive).long[]
generateLongArray(long min, long max, long amount)
Generate an array of randomlong
integers containing the values betweenstart
andstop
(inclusive) --- parameters must be in an integer range.Methods inherited from class edu.gvsu.kurmasz.warszawa.listgen.IntegerListGenerator
generateIntList, generateLongList
-
Constructor Details
-
RandomWithDuplicates
public RandomWithDuplicates(java.util.Random rin)Constructor allowing user to specify whichjava.util.Random
object to use.- Parameters:
rin
- the desiredjava.util.Random
object.
-
RandomWithDuplicates
public RandomWithDuplicates()Default constructor. Generates a newRandom
object.
-
-
Method Details
-
generateLongArray
public long[] generateLongArray(long min, long max, long amount)Generate an array of randomlong
integers containing the values betweenstart
andstop
(inclusive) --- parameters must be in an integer range.- Specified by:
generateLongArray
in classIntegerListGenerator
- Parameters:
min
- the minimum value that may appear. For now,Integer.MIN_VALUE
≤min
≤Integer.MAX_VALUE
.max
- the maximum value that may appear. For now,Integer.MIN_VALUE
≤min
≤Integer.MAX_VALUE
. Also,max <= min + Integer.MAX_VALUE
.amount
- the number of integers to generate. Must be>= 1
and< Integer.MAX_VALUE
.- Returns:
- an array of
long
integers. - Throws:
java.lang.IllegalArgumentException
- if the parameters specify an array that is too large, or if any of the parameters is out of range.
-
generateIntArray
public int[] generateIntArray(int min, int max, int amount)Generate an array ofamount
random integers containing the values betweenmin
andmax
(inclusive).- Overrides:
generateIntArray
in classIntegerListGenerator
- Parameters:
min
- the minimum value that may appearmax
- the maximum value that may appear. Must be>= min
and<= (min + Integer.MAX_VALUE)
amount
- the number of integers to generate. Must be>= 1
.- Returns:
- an array of integers.
- Throws:
java.lang.IllegalArgumentException
- if the parameters specify an array that is too large.
-