Buggy code:
public class Broker { private Map < PlayerNumber , Hand > holdings ; private ResourceInvoice tradeOffer = null ; private long randomSeed ; public Broker ( ) { } public Broker ( TransportBank resources , TransportDeck bankDevCard , Collection < TransportPlayer > playerList , Map < PlayerNumber , Collection < Harbor > > harborMap ) { } public TransportPlayer getTransportPlayer ( TransportPlayer transportPlayer , PlayerNumber playerNumber ) { } public TransportBank getTransportBank ( ) { } public TransportDeck getTransportDeck ( ) { } public TransportTradeOffer getTransportTradeOffer ( ) { } public long getRandomSeed ( ) { } public void setRandomSeed ( long seed ) { } public boolean processInvoice ( ResourceInvoice invoice ) throws CatanException { } private ResourceInvoice setInvoiceResource ( ResourceInvoice invoice , ResourceType resource , int quantity ) { } public ResourceInvoice randomRobPlayer ( PlayerNumber playerIndex , PlayerNumber victim ) { if ( victim == ( PlayerNumber . BANK ) ) { return null ; } ResourceInvoice invoice = new ResourceInvoice ( victim , playerIndex ) ; RandomNumberGenerator rng = RandomNumberGenerator . getInstance ( this . randomSeed ) ; <START_BUG> int rand = rng . generate ( 0 , this . getResourceCardCount ( victim , ALL ) ) ; <END_BUG> PlayerHoldings holdings = ( ( PlayerHoldings ) ( this . getHoldings ( ) . get ( victim ) ) ) ; int brickCount = holdings . getResourceCardCount ( BRICK ) ; int oreCount = holdings . getResourceCardCount ( ORE ) ; int sheepCount = holdings . getResourceCardCount ( SHEEP ) ; int wheatCount = holdings . getResourceCardCount ( WHEAT ) ; int woodCount = holdings . getResourceCardCount ( WOOD ) ; if ( rand < brickCount ) { invoice . setBrick ( 1 ) ; return invoice ; } rand -= brickCount ; if ( rand < oreCount ) { invoice . setOre ( 1 ) ; return invoice ; } rand -= oreCount ; if ( rand < sheepCount ) { invoice . setSheep ( 1 ) ; return invoice ; } rand -= sheepCount ; if ( rand < wheatCount ) { invoice . setWheat ( 1 ) ; return invoice ; } rand -= wheatCount ; if ( rand < woodCount ) { invoice . setWood ( 1 ) ; return invoice ; } return null ; } public void processMonopoly ( PlayerNumber player , ResourceType resource ) throws CatanException { } public void processYearOfPlenty ( PlayerNumber playerIndex , ResourceType resource1 , ResourceType resource2 ) throws CatanException { } public void processMonument ( PlayerNumber player ) { } public void processRoadBuilding ( PlayerNumber playerIndex ) { } public void processSoldier ( PlayerNumber player ) { } private boolean tradeCards ( Hand srcPlayer , Hand dstPlayer , ResourceType type , int count ) throws CatanException { } public boolean canPurchase ( PlayerNumber player , PropertyType type ) throws CatanException { } public void purchase ( PlayerNumber player , PropertyType type ) throws CatanException { } private DevelopmentCard drawDevelopmentCard ( ) throws CatanException { } public boolean canPlayDevelopmentCard ( PlayerNumber player , DevCardType type ) throws CatanException { } public int getDevelopmentCardCount ( PlayerNumber player , DevCardType type ) throws CatanException { } public boolean playDevelopmentCard ( PlayerNumber player , DevCardType type ) throws CatanException { } public boolean canMaritimeTrade ( PlayerNumber player , ResourceType type ) { } public int findBestRatio ( PlayerNumber player , ResourceType type ) { } public boolean canOfferTrade ( ResourceInvoice invoice ) { } public boolean canAcceptTrade ( ResourceInvoice invoice ) { } public boolean hasNecessaryResourceAmount ( PlayerNumber player , ResourceType resourceType , int requiredQuantity ) { } public boolean hasHarbor ( PlayerNumber player ) throws CatanException { } public boolean hasDevelopmentCard ( PlayerNumber player ) { } public void makeDevelopmentCardsPlayable ( PlayerNumber player ) throws CatanException { } public Map < PlayerNumber , Hand > getHoldings ( ) { } public int getResourceCardCount ( PlayerNumber player , ResourceType resource ) { } public int getNumberToDiscard ( PlayerNumber playerIndex ) { } public int getNumberOfPlayedSoldiers ( PlayerNumber player ) throws CatanException { } }

Fix:
int rand = rng . generate ( 0 , ( ( this . getResourceCardCount ( victim , ALL ) ) - 1 ) ) ;