Buggy code:
public class AffinityGenerator extends IntegerGenerator { public static final double ZIPFIAN_CONSTANT = 0.99 ; public static final long ITEM_COUNT = 10000000000L ; long lastTime ; long items = AffinityGenerator . ITEM_COUNT ; long min = 0L ; long max = AffinityGenerator . ITEM_COUNT ; long base = 0L ; double zipfianconstant = AffinityGenerator . ZIPFIAN_CONSTANT ; double alpha ; double zetan ; double eta ; double theta ; double zeta2theta ; long countforzeta ; boolean scrambled = false ; boolean mirrored = true ; int numHotSpots = 0 ; double percentAccessHotSpots = 0.0 ; boolean randomHotSpots = false ; boolean isRandom = true ; long lastItem = Long . MIN_VALUE ; ArrayList < Long > hotSpots = new ArrayList < Long > ( ) ; TreeMap < Double , Long > itemMap ; boolean allowitemcountdecrease = false ; public AffinityGenerator ( long _items ) { } public AffinityGenerator ( long _min , long _max ) { } public AffinityGenerator ( long _items , double _zipfianconstant ) { } public AffinityGenerator ( long min , long max , double _zipfianconstant ) { } public AffinityGenerator ( long min , long max , double _zipfianconstant , double _zetan ) { } public boolean getScrambled ( ) { } public boolean getMirrored ( ) { } public boolean getIsRandom ( ) { } public long getLastItem ( ) { } public int getNumHotSpots ( ) { } public ArrayList < Long > getHotSpots ( ) { } public double getPercentAccessHotSpots ( ) { } public boolean getRandomHotSpots ( ) { } public void setScrambled ( boolean scrambled ) { } public void setMirrored ( boolean mirrored ) { } public void setIsRandom ( boolean isRandom ) { } public void setLastItem ( long lastItem ) { } public void resetLastItem ( ) { } public void setNumHotSpots ( int numHotSpots ) { } public void setPercentAccessHotSpots ( double percentAccessHotSpots ) { } public void setRandomHotSpots ( boolean randomHotSpots ) { } double zeta ( long n , double theta ) { } static double zetastatic ( long n , double theta ) { } double zeta ( long st , long n , double theta , double initialsum ) { } static double zetastatic ( long st , long n , double theta , double initialsum ) { } void generateItemMap ( ) { } public int nextInt ( int itemcount , double shift ) { } public int nextInt ( double r1 , double r2 , int r3 , double shift ) { } public long nextLong ( long itemcount , double shift ) { } public long nextLong ( long itemcount , double r1 , double r2 , int r3 , double shift ) { <START_BUG> long totalShift = ( ( long ) ( itemcount * shift ) ) % itemcount ; <END_BUG> if ( ! ( isRandom ) ) { if ( ( lastItem ) == ( Long . MIN_VALUE ) ) { lastItem = totalShift ; } else { lastItem = ( ( lastItem ) + 1 ) % itemcount ; } setLastInt ( ( ( int ) ( lastItem ) ) ) ; return lastItem ; } if ( itemcount != ( countforzeta ) ) { synchronized ( this ) { if ( itemcount > ( countforzeta ) ) { zetan = zeta ( countforzeta , itemcount , theta , zetan ) ; if ( ( theta ) >= 1 ) { generateItemMap ( ) ; } else { eta = ( 1 - ( Math . pow ( ( 2.0 // ( items ) ) , ( 1 - ( theta ) ) ) ) ) // ( 1 - ( ( zeta2theta ) // ( zetan ) ) ) ; } } else if ( ( itemcount < ( countforzeta ) ) && ( allowitemcountdecrease ) ) { System . err . println ( ( ( ( ( "WARNING:<seq2seq4repair_space>Recomputing<seq2seq4repair_space>Zipfian<seq2seq4repair_space>distribtion.<seq2seq4repair_space>This<seq2seq4repair_space>is<seq2seq4repair_space>slow<seq2seq4repair_space>and<seq2seq4repair_space>should<seq2seq4repair_space>be<seq2seq4repair_space>avoided.<seq2seq4repair_space>(itemcount=" + itemcount ) + "<seq2seq4repair_space>countforzeta=" ) + ( countforzeta ) ) + ")" ) ) ; zetan = zeta ( itemcount , theta ) ; if ( ( theta ) >= 1 ) { generateItemMap ( ) ; } else { eta = ( 1 - ( Math . pow ( ( 2.0 // ( items ) ) , ( 1 - ( theta ) ) ) ) ) // ( 1 - ( ( zeta2theta ) // ( zetan ) ) ) ; } } } } double u = r1 ; double uz = u * ( zetan ) ; long ret ; if ( r2 < ( this . percentAccessHotSpots ) ) { int index = r3 ; ret = hotSpots . get ( index ) ; } else if ( ( theta ) >= 1 ) { if ( u < 0.95 ) { ret = itemMap . floorEntry ( u ) . getValue ( ) ; } else { Long maxItem = itemMap . lastEntry ( ) . getValue ( ) ; ret = ( ( Utils . random ( ) . nextInt ( ) ) % ( ( items ) - maxItem ) ) + maxItem ; if ( ret < maxItem ) ret += ( items ) - maxItem ; } } else { if ( uz < 1.0 ) { ret = 0 ; } else if ( uz < ( 1.0 + ( Math . pow ( 0.5 , theta ) ) ) ) { ret = 1 ; } else { ret = ( base ) + ( ( long ) ( itemcount * ( Math . pow ( ( ( ( ( eta ) * u ) - ( eta ) ) + 1 ) , alpha ) ) ) ) ; } }

Fix:
long totalShift = ( Math . round ( ( itemcount * shift ) ) ) % itemcount ;