org.limewire.collection
Class RandomSequence
java.lang.Object
org.limewire.collection.RandomSequence
- All Implemented Interfaces:
- Iterable<Integer>
public class RandomSequence
- extends Object
- implements Iterable<Integer>
Generates all the integers from 0 to a certain limit in a
random fashion where each number is generated only once per cycle.
RandomSequence also implements the Iterable
interface that iterates over a single cycle.
For more information regarding the logic, see Linear
congruential generator.
Thanks to Cyclonus for the pow2 hint.
for(Integer o : new RandomSequence(10))
System.out.println(o);
Random Output:
4
7
2
5
0
3
1
8
6
9
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RandomSequence
public RandomSequence(int end)
nextInt
public int nextInt()
iterator
public Iterator<Integer> iterator()
- Specified by:
iterator in interface Iterable<Integer>
Copyright © 2008 Lime Wire LLC. All Rights Reserved.