// TODO: find more triplets for different n sclass TripletLSFR { // params int n; int start = 1; int a, b, c; // the triplet // changing variables int step, value; // tap bit mask for different n's (2 through 24) static final int[] tapTable = { 0x3, 0x3, 0x3, 0x5, 0x3, 0x3, 0x2d, 0x11, 0x9, 0x5, 0x107, 0x27, 0x1007, 0x3, 0x100b, 0x9, 0x81, 0x27, 0x9, 0x5, 0x3, 0x21, 0x87 }; *(int *n, int *a, int *b, int *c) { value = start; } int cycleLength() { ret (1 << n)-1; } int next() { int mask = ((1 << n)-1); step = (step+1) & mask; int x = value; x ^= x << a; x ^= x >> b; x ^= x << c; ret value = x & mask; } }