Buffer { CharSequence subSequence(int from, int end) { StringBuilder sb = new StringBuilder(); Integer frm = null; final List<Integer> sgmnts = segments(from, end); for (Integer i1 : sgmnts) { if (frm == null) { frm = i1; continue; } sb.append(buf.subSequence(frm, i1)); frm = null; } return sb; } Buffer(CharSequence sb, int segmentLen, long seed);   }
@Test public void splitAndRandomize() { long seed = System.currentTimeMillis(); Buffer b = new Buffer(lng, 3, seed); for (int i = 0; i < lng.length(); i++) { for (int j = i; j < lng.length(); j++) { CharSequence mangled = b.subSequence(i, j); CharSequence real = lng.subSequence(i, j); assertEquals(mangled.toString(), real.toString(), "At seed " + seed + " subSequence(" + i + ", " + j + ") are the same"); } } }