A bug fix for all versions of the JDK.  The JDK appears to
use all four bytes in an integer as independent byte values!
Totally wrong. I've submitted a bug report.
491467
@Override
	public void nextBytes(final byte[] bytes)    
        {
        for (int x=0;x<bytes.length;x++) bytes[x] = (byte)next(8);
        }

    /** For completeness' sake, though it's not in java.util.Random.  
     * @return ? */
    public char nextChar()
        {
        // chars are 16-bit UniCode values
        return (char)(next(16));
        }

    /** For completeness' sake, though it's not in java.util.Random. 
     * @return ? */
    public short nextShort()
        {
        return (short)(next(16));
        }

    /** For completeness' sake, though it's not in java.util.Random.  
     * @return ? */
    public byte nextByte()
        {
        return (byte)(next(8));
        }


    /** A bug fix for all JDK code including 1.2.  nextGaussian can theoretically
        ask for the log of 0 and divide it by 0! See Java bug 
        <a href="http://developer.java.sun.com/developer/bugParade/bugs/4254501.html">
        http://developer.java.sun.com/developer/bugParade/bugs/4254501.html</a>
     * @return ?
    */
    @Override
	synchronized public double nextGaussian() 
        {
        if (__haveNextNextGaussian) 
            {
            __haveNextNextGaussian = false;
            return __nextNextGaussian;
            }
//        else 
//            {
            double v1, v2, s;
            do 
                { 
                v1 = 2 * nextDouble() - 1; // between -1.0 and 1.0
                v2 = 2 * nextDouble() - 1; // between -1.0 and 1.0
                s = v1 * v1 + v2 * v2;
                } while (s >= 1 || s==0 );
            double multiplier = /*Strict*/Math.sqrt(-2 * /*Strict*/Math.log(s)/s);
            __nextNextGaussian = v2 * multiplier;
            __haveNextNextGaussian = true;
            return v1 * multiplier;
            }
//        }
    
    /**
     * Tests the code.
     * @param args 
     */
    public static void main(String args[])
        { 
        int j;

        MersenneTwister r;

        // CORRECTNESS TEST
        // COMPARE WITH http://www.math.keio.ac.jp/matumoto/CODES/MT2002/mt19937ar.out
        
        r = new MersenneTwister(new int[]{0x123, 0x234, 0x345, 0x456});
        System.out.println("Output of MersenneTwister with new (2002/1/26) seeding mechanism");
        for (j=0;j<1000;j++)
            {
            // first, convert the int from signed to "unsigned"
            long l = r.nextInt();
            if (l < 0 ) l += 4294967296L;  // max int value
            String s = String.valueOf(l);
            while(s.length() < 10) s = " " + s;  // buffer
            System.out.print(s + " ");
            if (j%5==4) System.out.println();       
            }

        // SPEED TEST

        final long SEED = 4357;

        int xx; long ms;
        System.out.println("\nTime to test grabbing 100000000 ints");
          
        r = new MersenneTwister(SEED);
        ms = System.currentTimeMillis();
        xx=0;
        for (j = 0; j < 100000000; j++)
            xx += r.nextInt();
        System.out.println("Mersenne Twister: " + (System.currentTimeMillis()-ms) + "          Ignore this: " + xx);

        System.out.println("To compare this with java.util.Random, run this same test on MersenneTwisterFast.");
        System.out.println("The comparison with Random is removed from MersenneTwister because it is a proper");
        System.out.println("subclass of Random and this unfairly makes some of Random's methods un-inlinable,");
        System.out.println("so it would make Random look worse than it is.");

        // TEST TO COMPARE TYPE CONVERSION BETWEEN
        // MersenneTwisterFast.java AND MersenneTwister.java

        
        System.out.println("\nGrab the first 1000 booleans");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextBoolean() + " ");
            if (j%8==7) System.out.println();
            }
        if (!(j%8==7)) System.out.println();
          
        System.out.println("\nGrab 1000 booleans of increasing probability using nextBoolean(double)");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextBoolean(j / 999.0) + " ");
            if (j%8==7) System.out.println();
            }
        if (!(j%8==7)) System.out.println();
          
        System.out.println("\nGrab 1000 booleans of increasing probability using nextBoolean(float)");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextBoolean(j / 999.0f) + " ");
            if (j%8==7) System.out.println();
            }
        if (!(j%8==7)) System.out.println();
          
        byte[] bytes = new byte[1000];
        System.out.println("\nGrab the first 1000 bytes using nextBytes");
        r = new MersenneTwister(SEED);
        r.nextBytes(bytes);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(bytes[j] + " ");
            if (j%16==15) System.out.println();
            }
        if (!(j%16==15)) System.out.println();
        
        byte b;
        System.out.println("\nGrab the first 1000 bytes -- must be same as nextBytes");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print((b = r.nextByte()) + " ");
            if (b!=bytes[j]) System.out.print("BAD ");
            if (j%16==15) System.out.println();
            }
        if (!(j%16==15)) System.out.println();

        System.out.println("\nGrab the first 1000 shorts");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextShort() + " ");
            if (j%8==7) System.out.println();
            }
        if (!(j%8==7)) System.out.println();

        System.out.println("\nGrab the first 1000 ints");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextInt() + " ");
            if (j%4==3) System.out.println();
            }
        if (!(j%4==3)) System.out.println();

        System.out.println("\nGrab the first 1000 ints of different sizes");
        r = new MersenneTwister(SEED);
        int max = 1;
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextInt(max) + " ");
            max *= 2;
            if (max <= 0) max = 1;
            if (j%4==3) System.out.println();
            }
        if (!(j%4==3)) System.out.println();

        System.out.println("\nGrab the first 1000 longs");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextLong() + " ");
            if (j%3==2) System.out.println();
            }
        if (!(j%3==2)) System.out.println();

        System.out.println("\nGrab the first 1000 longs of different sizes");
        r = new MersenneTwister(SEED);
        long max2 = 1;
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextLong(max2) + " ");
            max2 *= 2;
            if (max2 <= 0) max2 = 1;
            if (j%4==3) System.out.println();
            }
        if (!(j%4==3)) System.out.println();
          
        System.out.println("\nGrab the first 1000 floats");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextFloat() + " ");
            if (j%4==3) System.out.println();
            }
        if (!(j%4==3)) System.out.println();

        System.out.println("\nGrab the first 1000 doubles");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextDouble() + " ");
            if (j%3==2) System.out.println();
            }
        if (!(j%3==2)) System.out.println();

        System.out.println("\nGrab the first 1000 gaussian doubles");
        r = new MersenneTwister(SEED);
        for (j = 0; j < 1000; j++)
            {
            System.out.print(r.nextGaussian() + " ");
            if (j%3==2) System.out.println();
            }
        if (!(j%3==2)) System.out.println();
        
        }
    
    }
594236
static public int asInt(byte[] array) {

        if (null == array || 4 != array.length) {
            throw new IllegalArgumentException("Length of the byte array should be 4");
        }

        return ((array[0] << 24)
                + ((array[1] & 255) << 16)
                + ((array[2] & 255) << 8) + (array[3] & 255));
    }
358955
static int getInt (ByteBuffer buffer) {
        int v = buffer.get();
        int value = v & 0x7F;
        if ((v & 0x80) != 0) {
            v = buffer.get();
            value |= (v & 0x7F) << 7;
            if ((v & 0x80) != 0) {
                v = buffer.get();
                value |= (v & 0x7F) << 14;
                if ((v & 0x80) != 0) {
                    v = buffer.get();
                    value |= (v & 0x7F) << 21;
                    if ((v & 0x80) != 0) {
                        v = buffer.get();
                        value |= (v & 0x7F) << 28;
                    }
                }
            }
        }
        value = (value >>> 1) ^ (-(value & 1));
        return value;
    }
171356
def to_java_ints(m):
    '''
    
    '''
    global _java
    if _java is None: _init_registration()
    m = np.asarray(m)
    dims = len(m.shape)
    if dims > 2: raise ValueError('1D and 2D arrays supported only')
    bindat = serialize_numpy(m, 'i')
    return (_java.jvm.nben.util.Numpy.int2FromBytes(bindat) if dims == 2
            else _java.jvm.nben.util.Numpy.int1FromBytes(bindat))
1359340
public final void mDecimalLiteral() throws RecognitionException {
		try {
			int _type = DecimalLiteral;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:16: ( ( '0' | NonZeroDigit ( ( Digits )? | Underscores Digits ) ) ( IntegerTypeSuffix )? )
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:18: ( '0' | NonZeroDigit ( ( Digits )? | Underscores Digits ) ) ( IntegerTypeSuffix )?
			{
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:18: ( '0' | NonZeroDigit ( ( Digits )? | Underscores Digits ) )
			int alt5=2;
			int LA5_0 = input.LA(1);
			if ( (LA5_0=='0') ) {
				alt5=1;
			}
			else if ( ((LA5_0 >= '1' && LA5_0 <= '9')) ) {
				alt5=2;
			}

			else {
				NoViableAltException nvae =
					new NoViableAltException("", 5, 0, input);
				throw nvae;
			}

			switch (alt5) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:19: '0'
					{
					match('0'); 
					}
					break;
				case 2 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:25: NonZeroDigit ( ( Digits )? | Underscores Digits )
					{
					mNonZeroDigit(); 

					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:38: ( ( Digits )? | Underscores Digits )
					int alt4=2;
					int LA4_0 = input.LA(1);
					if ( (LA4_0=='_') ) {
						alt4=2;
					}

					else {
						alt4=1;
					}

					switch (alt4) {
						case 1 :
							// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:39: ( Digits )?
							{
							// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:39: ( Digits )?
							int alt3=2;
							int LA3_0 = input.LA(1);
							if ( ((LA3_0 >= '0' && LA3_0 <= '9')) ) {
								alt3=1;
							}
							switch (alt3) {
								case 1 :
									// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:39: Digits
									{
									mDigits(); 

									}
									break;

							}

							}
							break;
						case 2 :
							// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:49: Underscores Digits
							{
							mUnderscores(); 

							mDigits(); 

							}
							break;

					}

					}
					break;

			}

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1304:70: ( IntegerTypeSuffix )?
			int alt6=2;
			int LA6_0 = input.LA(1);
			if ( (LA6_0=='L'||LA6_0=='l') ) {
				alt6=1;
			}
			switch (alt6) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:
					{
					if ( input.LA(1)=='L'||input.LA(1)=='l' ) {
						input.consume();
					}
					else {
						MismatchedSetException mse = new MismatchedSetException(null,input);
						recover(mse);
						throw mse;
					}
					}
					break;

			}

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
460563
@Override
	public void writeIntUnchecked(int v) throws IOException {
		outputStream.write(0xFF & v);
		outputStream.write(0xFF & (v >> 8));
		outputStream.write(0xFF & (v >> 16));
		outputStream.write(0xFF & (v >> 24));
		bytesWritten += 4;
	}
1049211
static int readRawVarint32(final DataInput input, final byte firstByte) throws IOException
    {
        int result = firstByte & 0x7f;
        int offset = 7;
        for (; offset < 32; offset += 7)
        {
            final byte b = input.readByte();
            result |= (b & 0x7f) << offset;
            if ((b & 0x80) == 0)
            {
                return result;
            }
        }
        // Keep reading up to 64 bits.
        for (; offset < 64; offset += 7)
        {
            final byte b = input.readByte();
            if ((b & 0x80) == 0)
            {
                return result;
            }
        }
        throw ProtobufException.malformedVarint();
    }
317538
public final void synpred244_Java_fragment() throws RecognitionException {
		// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1211:8: ( '(' primitiveType ')' unaryExpression )
		// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1211:8: '(' primitiveType ')' unaryExpression
		{
		match(input,36,FOLLOW_36_in_synpred244_Java5610); if (state.failed) return;
		pushFollow(FOLLOW_primitiveType_in_synpred244_Java5612);
		primitiveType();
		state._fsp--;
		if (state.failed) return;
		match(input,37,FOLLOW_37_in_synpred244_Java5614); if (state.failed) return;
		pushFollow(FOLLOW_unaryExpression_in_synpred244_Java5616);
		unaryExpression();
		state._fsp--;
		if (state.failed) return;
		}

	}
101301
public static long varIntBytesToLong(byte[] bytes, int offset) {
        int shift = 0;
        long result = 0;
        while (shift < 64) {
            final byte b = bytes[offset++];
            result |= (long)(b & 0x7F) << shift;
            if ((b & 0x80) == 0) {
                return result;
            }
            shift += 7;
        }
        throw new IllegalStateException("Varint representation is invalid or exceeds 64-bit value");
    }
532099
static public void packInt(DataOutput out, int value) throws IOException {
       // Optimize for the common case where value is small. This is particular important where our caller
       // is SerializerBase.SER_STRING.serialize because most chars will be ASCII characters and hence in this range.
       // credit Max Bolingbroke https://github.com/jankotek/MapDB/pull/489

        int shift = (value & ~0x7F); //reuse variable
        if (shift != 0) {
            //$DELAY$
            shift = 31-Integer.numberOfLeadingZeros(value);
            shift -= shift%7; // round down to nearest multiple of 7
            while(shift!=0){
                out.writeByte((byte) ((value>>>shift) & 0x7F));
                //$DELAY$
                shift-=7;
            }
        }
        //$DELAY$
        out.writeByte((byte) ((value & 0x7F)|0x80));
    }
553921
protected void init() throws IOException {
      if (isInited) return;

      byte bom[] = new byte[BOM_SIZE];
      int n, unread;
      n = internalIn.read(bom, 0, bom.length);

      if ( (bom[0] == (byte)0x00) && (bom[1] == (byte)0x00) &&
                  (bom[2] == (byte)0xFE) && (bom[3] == (byte)0xFF) ) {
         encoding = "UTF-32BE";
         unread = n - 4;
      } else if ( (bom[0] == (byte)0xFF) && (bom[1] == (byte)0xFE) &&
                  (bom[2] == (byte)0x00) && (bom[3] == (byte)0x00) ) {
         encoding = "UTF-32LE";
         unread = n - 4;
      } else if (  (bom[0] == (byte)0xEF) && (bom[1] == (byte)0xBB) &&
            (bom[2] == (byte)0xBF) ) {
         encoding = "UTF-8";
         unread = n - 3;
      } else if ( (bom[0] == (byte)0xFE) && (bom[1] == (byte)0xFF) ) {
         encoding = "UTF-16BE";
         unread = n - 2;
      } else if ( (bom[0] == (byte)0xFF) && (bom[1] == (byte)0xFE) ) {
         encoding = "UTF-16LE";
         unread = n - 2;
      } else {
         // Unicode BOM mark not found, unread all bytes
         encoding = defaultEnc;
         unread = n;
      }      
      //System.out.println("read=" + n + ", unread=" + unread);

      if (unread > 0) internalIn.unread(bom, (n - unread), unread);

      isInited = true;
   }
1133236
public static void writeBytes(byte[] bytes, long value, int offset, int numBytes) {
        int shift = 0;
        for(int i = offset + numBytes - 1; i >= offset; i--) {
            bytes[i] = (byte) (0xFF & (value >> shift));
            shift += 8;
        }
    }
1223800
public static void displayByteArray(byte[] record) {
        int i;
        for (i = 0; i < record.length - 1; i++) {
            if (i % 16 == 0) {
                System.out.println();
            }
            System.out.print(Integer.toHexString(record[i] >> 4 & 0x0F));
            System.out.print(Integer.toHexString(record[i] & 0x0F));
            System.out.print(",");
        }
        System.out.print(Integer.toHexString(record[i] >> 4 & 0x0F));
        System.out.print(Integer.toHexString(record[i] & 0x0F));
        System.out.println();
    }
1317355
@FFDCIgnore(NumberFormatException.class)
    private static boolean determineIsJava8Before161(String version) {
        try {
            return version != null 
                && version.startsWith("1.8.0_")
                && Integer.parseInt(version.substring(6)) < 161;
        } catch (NumberFormatException ex) {
            //no-op
        }
        return false;
    }
164672
protected void init() throws IOException {
		if (isInited) {
			return;
		}

		byte bom[] = new byte[BOM_SIZE];
		int n, unread;
		n = in.read(bom, 0, bom.length);

		if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
			charset = "UTF-32BE";
			unread = n - 4;
		} else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
			charset = "UTF-32LE";
			unread = n - 4;
		} else if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
			charset = "UTF-8";
			unread = n - 3;
		} else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
			charset = "UTF-16BE";
			unread = n - 2;
		} else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
			charset = "UTF-16LE";
			unread = n - 2;
		} else {
			// Unicode BOM mark not found, unread all bytes
			charset = defaultCharset;
			unread = n;
		}
		// System.out.println("read=" + n + ", unread=" + unread);

		if (unread > 0) {
			in.unread(bom, (n - unread), unread);
		}

		isInited = true;
	}
210620
private long fourByteToLong(byte[] bytes, int offset) {
        return (byteToLong(bytes[offset + 0])
                + (byteToLong(bytes[offset + 1]) << 8)
                + (byteToLong(bytes[offset + 2]) << 16)
                + (byteToLong(bytes[offset + 3]) << 24));
    }
611273
final void writeInt(int value)
    {
        byte writeBuffer[] = new byte[4];
        writeBuffer[0] = (byte) (value >>> 24);
        writeBuffer[1] = (byte) (value >>> 16);
        writeBuffer[2] = (byte) (value >>> 8);
        writeBuffer[3] = (byte) (value >>> 0);
        write(writeBuffer, 0, 4);
    }