/** * Generate and return a random String that match the pattern used in this Generex. * * @return */ public String random() { return prepareRandom("", automaton.getInitialState(), 1, Integer.MAX_VALUE); }
/** * Generate and return a random String that match the pattern used in this Generex. * * @return */ public String random() { return prepareRandom("", automaton.getInitialState(), 1, Integer.MAX_VALUE); }
/** * Generate and return a random String that match the pattern used in this Generex, and the string has a length >= <code>minLength</code> * * @param minLength * @return */ public String random(int minLength) { return prepareRandom("", automaton.getInitialState(), minLength, Integer.MAX_VALUE); }
/** * Generate and return a random String that match the pattern used in this Generex, and the string has a length >= * <code>minLength</code> * * @param minLength * @return */ public String random(int minLength) { return prepareRandom("", automaton.getInitialState(), minLength, Integer.MAX_VALUE); }
/** * Generate and return a random String that match the pattern used in this Generex, and the string has a length >= * <code>minLength</code> and <= <code>maxLength</code> * * @param minLength * @param maxLength * @return */ public String random(int minLength, int maxLength) { return prepareRandom("", automaton.getInitialState(), minLength, maxLength); }
/** * Generate and return a random String that match the pattern used in this Generex, and the string has a length >= <code>minLength</code> and <= * <code>maxLength</code> * * * @param minLength * @param maxLength * @return */ public String random(int minLength, int maxLength) { return prepareRandom("", automaton.getInitialState(), minLength, maxLength); }
result = prepareRandom(strMatch + randomChar, randomTransition.getDest(), minLength, maxLength); int resultLength = result.length(); if (minLength <= resultLength && resultLength <= maxLength) {
private String prepareRandom(String strMatch, State state, int minLength, int maxLength) { List<Transition> transitions = state.getSortedTransitions(false); Set<Integer> selectedTransitions = new HashSet<Integer>(); String result = strMatch; for (int resultLength = -1; transitions.size() > selectedTransitions.size() && (resultLength < minLength || resultLength > maxLength); resultLength = result.length()) { if (randomPrepared(strMatch, state, minLength, maxLength, transitions)) { return strMatch; } int nextInt = random.nextInt(transitions.size()); if (!selectedTransitions.contains(nextInt)) { selectedTransitions.add(nextInt); Transition randomTransition = transitions.get(nextInt); int diff = randomTransition.getMax() - randomTransition.getMin() + 1; int randomOffset = diff > 0 ? random.nextInt(diff) : diff; char randomChar = (char) (randomOffset + randomTransition.getMin()); result = prepareRandom(strMatch + randomChar, randomTransition.getDest(), minLength, maxLength); } } return result; }