A good way to generate non-repeating random sequences is to use LFSR .
public class LFSR implements Iterable<BigInteger> {
Now you need to use the value 8+8+8=24 .
The use is simple.
public void test() { // Sample 24-bit tap found on page 5 of // http://www.xilinx.com/support/documentation/application_notes/xapp052.pdf int[] taps = new int[]{24, 23, 22, 17}; LFSR lfsr = new LFSR(taps); int count = 100; for (BigInteger i : lfsr) { System.out.println("Colour: " + new Color(i.intValue())); if (--count <= 0) { break; } } }
Features of LFSR:
- It will be repeated, but not until all possible bit patterns (except
0 ) are created. - The generated number is a statistically good random number.
- The same sequence will be generated each time (select a different
tap if you want a different sequence).
To achieve the required interval, I suggest you add a filter and drop everything that is too close (by your criteria) to the previous one.
source share