code: public String generate(int total, final int bad) {
  		if (total < 0) {
  			if (log.isDebugEnabled()) {
  				log.debug("Character string cannot have a negative length!");
  			}
  			total = 0;
  		}
  		Range[] ranges = getRanges();
  		int[] lengths = new int[ranges.length];
  		int length = 0;
  		// first make sure every single node has at least its minimum length
  		for (int i = 0; i < ranges.length; i++) {
  			lengths[i] = ranges[i].getMin();
  			length += lengths[i];
  		}
  		// now increase each node chosen randomly by one until the extra is consumed
  		int index = 0;
  		boolean increase = length < total;
  		if (increase) {
  			boolean maxedOut = total > getRange().getMax();
  			while (length < total) {
  				// if maxed out is true, we have more than normal max characters, so
  				// we ignore the local max; if not maxed out, the nodes are not bigger than max
  				if ((maxedOut || ranges[index].getMax() > lengths[index]) && choice.get()) {
  					lengths[index]++;
  					length++;
  				}
  				index = (index + 1) % lengths.length;
  			}
  		} else {
  			boolean minOut = total < getRange().getMin();
  			while (length > total) {
  				// if min out is true, we have less than normal min characters, so
  				// we ignore the local min; if not min out, the nodes are not smaller than min
  				if ((minOut || ranges[index].getMin() > lengths[index]) && lengths[index] > 0 && choice.get()) {
  					lengths[index]--;
  					length--;
  				}
  				index = (index + 1) % lengths.length;
  			}
  		}
  		// now we have distributed the character number to all subnodes of this expression
  		// build buffer
  		return generate(lengths, bad);
  	}
docs: Generates a string with the given length. Thereby the mandatory length will be reached first
  and then the separate areas are filled with the remaining characters randlomly.