|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpeersim.util.RandPermutation
public class RandPermutation
This class provides a random permutation of indexes. Useful for random sampling without replacement.
Constructor Summary | |
---|---|
RandPermutation(int k,
java.util.Random r)
Sets source of randomness and initial size. |
|
RandPermutation(java.util.Random r)
Sets source of randomness to be used. |
Method Summary | |
---|---|
int |
get(int i)
Returns the ith element of the permutation set by setPermutation(int) . |
boolean |
hasNext()
Returns true if IndexIterator.next() can be called at least one more time. |
int |
next()
Next random sample without replacement |
void |
reset(int k)
It initiates a random permutation of the integers from 0 to k-1. |
void |
setPermutation(int k)
It calculates a random permutation of the integers from 0 to k-1. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RandPermutation(java.util.Random r)
reset(int)
to fully initialize the object.
r
- Source of randomnesspublic RandPermutation(int k, java.util.Random r)
setPermutation(int)
to fully initialize the object with a
permuation ready to use.
r
- Source of randomnessk
- size of permutationMethod Detail |
---|
public void setPermutation(int k)
get(int)
.
If the previous permutation was of the same length, it is more efficient.
Note that after calling this the object is reset, so next()
can
be called k times, even if get(int)
was called an arbitrary number of
times. Note however that mixing get(int)
and next()
results in
incorrect behavior for get(int)
(but next()
works fine).
The idea is to use this method only in connection with get(int)
.
public int get(int i)
setPermutation(int)
.
If next()
is called after setPermutation(int)
and before
this method, then the behavior of this method is unspecified.
public void reset(int k)
next()
.
Calls to get(int)
return undefined values, so next()
must be used.
If the previous permutation was of the same length, it is more efficient.
reset
in interface IndexIterator
public int next()
next
in interface IndexIterator
public boolean hasNext()
IndexIterator
IndexIterator.next()
can be called at least one more time.
Note that IndexIterator.next()
can be called k times after IndexIterator.reset(int)
.
hasNext
in interface IndexIterator
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |