The following demonstrates how to use Java language to retrieve random data from a SwiftRNG device when used in LInux environment. The following code will only work when running script or swrandom kernel module.

A sample source code in Java for retrieving random primitive values from a SwiftRNG device.

package swiftrng;


 * Java example for retrieving random Java primitives from a SwiftRNG device when used with Linux. 
public class RetrieveRandomPrimitives {
	public static void main(String[] args) throws IOException {
		// Read from /tmp/swiftrng when using script.  
		// Read from /dev/swrandom when using swrandom kernel module.
		DataInputStream dis = new DataInputStream(new FileInputStream("/dev/swrandom"));
		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