The following demonstrates how to use Java language to retrieve random data from an AlphaRNG device when used in LInux environment. The following code will only work when running run-alrng-pserver.sh script or alrandom kernel module.

A sample source code in Java for retrieving random primitive values from an AlphaRNG device.

package alpharng;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * 
 * Java example for retrieving random Java primitives from an AlphaRNG device when used with Linux. 
 *
 */
public class RetrieveRandomPrimitives {
	
	public static void main(String[] args) throws IOException {
		// Read from /tmp/alpharng when using run-alrng-pserver.sh script.  
		// Read from /dev/alrandom when using alrandom kernel module.
		DataInputStream dis = new DataInputStream(new FileInputStream("/dev/alrandom"));
		try {
			System.out.println("Random Integer: " + dis.readInt());
			System.out.println("Random Byte: " + dis.readByte());
			System.out.println("Random Unsigned Byte: " + dis.readUnsignedByte());
			System.out.println("Random Double: " + dis.readDouble());
			System.out.println("Random Float: " + dis.readFloat());
			System.out.println("Random Long: " + dis.readLong());
			System.out.println("Random Short: " + dis.readShort());
			System.out.println("Random Unsigned Short: " + dis.readUnsignedShort());
			
		} catch (IOException e) {
			// TODO Handle error
			e.printStackTrace();
		}
		dis.close();
	}

}