public class UniqueRandomSequence
extends java.lang.Object
UniqueRandomSequence sequence = new UniqueRandomSequence(10);
while (sequence.hasMore()) {
System.out.println(sequence.nextValue());
}
| Modifier and Type | Field and Description |
|---|---|
private int[] |
numbers
Array of the numbers to be used in the sequence.
|
private int |
numbersLeft
How many numbers are left in the sequence.
|
private java.util.Random |
random
Random number generator.
|
| Constructor and Description |
|---|
UniqueRandomSequence(int length)
Generate a random sequence with all the numbers from 0 up to
length-1. |
UniqueRandomSequence(int start,
int length,
int step)
Generate a random sequence in the specified range.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
hasMore()
Check whether there are more numbers in the sequence.
|
int |
nextValue()
Fetch the next number from the sequence.
|
private final int[] numbers
private final java.util.Random random
private int numbersLeft
public UniqueRandomSequence(int length)
length-1.length - the length of the sequencepublic UniqueRandomSequence(int start,
int length,
int step)
start - the smallest number in the sequencelength - the size of the sequencestep - the difference between adjacent numbers if the sequence is
sortedApache Derby V10.10 Internals - Copyright © 2004,2014 The Apache Software Foundation. All Rights Reserved.