if (useRand && rand.nextDouble() <= probRandom && !(Language.treebank().isNP(lhs) && lhs != Language.treebank().baseNPLabel())) {  int rhsLen = rhs.length(); return rand.nextInt(rhsLen) + 1; }
  protected int defaultFindHead(Symbol lhs, SexpList rhs) {    HeadFindInstruction[] instructions =      (HeadFindInstruction[])headFindInstructions.get(lhs);    if (instructions == null) {      if (warnDefaultRule)	System.err.println(getClass().getName() + ": warning: couldn't find " +			   "rule for " + lhs + " -> " + rhs);      instructions =	(HeadFindInstruction[])headFindInstructions.get(defaultSym);      if (instructions == null)	System.err.println(getClass().getName() + ": error: couldn't find " +			   "rule for " + lhs + " -> " + rhs +			   "\n\tand there is no default rule");    }    int headIdx = -1;    int rightmostIdx = rhs.size() - 1;    boolean direction = RIGHT;    for (int i = 0; i < instructions.length; i++) {      direction = instructions[i].direction;      Symbol[] scanSet = instructions[i].scanSet;      if (scanSet.length == 0) {	headIdx = (direction == LEFT ? 0 : rightmostIdx);	break;      }      headIdx = scan(direction, rhs, scanSet);      if (headIdx >= 0)	break;    }    // THIS IS A HACK TO HANDLE CASE WHEN ALL OF THE HEAD-FINDING INSTRUCTIONS    // FAIL: WE PICK THE CHILD ACCORDING TO THE SCAN DIRECTION SPECIFIED    // BY THE FINAL HEAD-FINDING INSTRUCTION    if (headIdx < 0)      headIdx = (direction == LEFT ? 0 : rightmostIdx);    return headIdx + 1;  }