void (EditorEx editor, Random random) { StringBuilder text = new StringBuilder(); int count = 1 + random.nextInt(MAX_CHARS_TO_ADD); for (int i = 0; i < count; i++) { text.append(CHARS_TO_USE.charAt(random.nextInt(CHARS_TO_USE.length()))); } Document document = editor.getDocument(); int offset = random.nextInt(document.getTextLength() + 1); WriteCommandAction.writeCommandAction(getProject()).run(() -> document.insertString(offset, text.toString())); }