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.Randomobject to use. -
Method Summary
Modifier and Type Method Description int[]generateIntArray(int min, int max, int amount)Generate an array ofamountrandom integers containing the values betweenminandmax(inclusive).long[]generateLongArray(long min, long max, long amount)Generate an array of randomlongintegers containing the values betweenstartandstop(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.Randomobject to use.- Parameters:
rin- the desiredjava.util.Randomobject.
-
RandomWithDuplicates
public RandomWithDuplicates()Default constructor. Generates a newRandomobject.
-
-
Method Details
-
generateLongArray
public long[] generateLongArray(long min, long max, long amount)Generate an array of randomlongintegers containing the values betweenstartandstop(inclusive) --- parameters must be in an integer range.- Specified by:
generateLongArrayin 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>= 1and< Integer.MAX_VALUE.- Returns:
- an array of
longintegers. - 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 ofamountrandom integers containing the values betweenminandmax(inclusive).- Overrides:
generateIntArrayin classIntegerListGenerator- Parameters:
min- the minimum value that may appearmax- the maximum value that may appear. Must be>= minand<= (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.
-