package simulator;

public class Reference {

    private static StringBuilder books = new StringBuilder();

    public static void readBooks(String... filenames){
        for (String filename : filenames) {
            books.append(Baudot.toBritishNotation(Baudot.readRawPlaintextFile(filename)));
        }
        while (books.length() < 1_000_000) {
            books.append(books);
        }
        books.setLength(1_000_000);
    }

    public static byte[] randomPlaintextSegment(int len) {
        int randomPos = Utils.random.nextInt(books.length() * 3/4);
        do {
            while (!books.substring(randomPos, randomPos + 2).equals("43")) {
                randomPos++;
                if (randomPos + len >= books.length()) {
                    randomPos = -1;
                    break;
                }
            }
        } while (randomPos == -1);
        randomPos += 2;
        return Baudot.fromBritishNotation(books.substring(randomPos, randomPos + len));
    }
}
