Buggy code:
public class RandomDataGenerator implements Serializable , RandomData { private static final long serialVersionUID = - 626730818244969716L ; private RandomGenerator rand = null ; private RandomGenerator secRand = null ; public RandomDataGenerator ( ) { } public RandomDataGenerator ( RandomGenerator rand ) { } public String nextHexString ( int len ) throws NotStrictlyPositiveException { } public int nextInt ( final int lower , final int upper ) throws NumberIsTooLargeException { } public long nextLong ( final long lower , final long upper ) throws NumberIsTooLargeException { } private static long nextLong ( final RandomGenerator rng , final long n ) throws IllegalArgumentException { if ( n > 0 ) { final byte [ ] byteArray = new byte [ 8 ] ; long bits ; long val ; do { rng . nextBytes ( byteArray ) ; bits = 0 ; for ( final byte b : byteArray ) { bits = ( bits << 8 ) | ( ( ( long ) ( b ) ) & 255L ) ; } <START_BUG> bits = bits & 9223372036854775807L ; <END_BUG> val = bits % n ; } while ( ( ( bits - val ) + ( n - 1 ) ) < 0 ) ; return val ; } throw new NotStrictlyPositiveException ( n ) ; } public String nextSecureHexString ( int len ) throws NotStrictlyPositiveException { } public int nextSecureInt ( final int lower , final int upper ) throws NumberIsTooLargeException { } public long nextSecureLong ( final long lower , final long upper ) throws NumberIsTooLargeException { } public long nextPoisson ( double mean ) throws NotStrictlyPositiveException { } public double nextGaussian ( double mu , double sigma ) throws NotStrictlyPositiveException { } public double nextExponential ( double mean ) throws NotStrictlyPositiveException { } public double nextGamma ( double shape , double scale ) throws NotStrictlyPositiveException { } public int nextHypergeometric ( int populationSize , int numberOfSuccesses , int sampleSize ) throws NotPositiveException , NotStrictlyPositiveException , NumberIsTooLargeException { } public int nextPascal ( int r , double p ) throws NotStrictlyPositiveException , OutOfRangeException { } public double nextT ( double df ) throws NotStrictlyPositiveException { } public double nextWeibull ( double shape , double scale ) throws NotStrictlyPositiveException { } public int nextZipf ( int numberOfElements , double exponent ) throws NotStrictlyPositiveException { } public double nextBeta ( double alpha , double beta ) { } public int nextBinomial ( int numberOfTrials , double probabilityOfSuccess ) { } public double nextCauchy ( double median , double scale ) { } public double nextChiSquare ( double df ) { } public double nextF ( double numeratorDf , double denominatorDf ) throws NotStrictlyPositiveException { } public double nextUniform ( double lower , double upper ) throws NotANumberException , NotFiniteNumberException , NumberIsTooLargeException { } public double nextUniform ( double lower , double upper , boolean lowerInclusive ) throws NotANumberException , NotFiniteNumberException , NumberIsTooLargeException { } public int [ ] nextPermutation ( int n , int k ) throws NotStrictlyPositiveException , NumberIsTooLargeException { } public Object [ ] nextSample ( Collection < ? > c , int k ) throws NotStrictlyPositiveException , NumberIsTooLargeException { } public void reSeed ( long seed ) { } public void reSeedSecure ( ) { } public void reSeedSecure ( long seed ) { } public void reSeed ( ) { } public void setSecureAlgorithm ( String algorithm , String provider ) throws NoSuchAlgorithmException , NoSuchProviderException { } public RandomGenerator getRandomGenerator ( ) { } private void initRan ( ) { } private RandomGenerator getSecRan ( ) { } }

Fix:
bits &= 9223372036854775807L ;