Class DevRandom

java.lang.Object
java.util.Random
com.aoapps.io.posix.linux.DevRandom
All Implemented Interfaces:
Serializable

public class DevRandom extends Random
This class acts as a direct source of Random data from /dev/random on Linux platforms. Many of these calls are platform-specific and use the included libaocode.so Linux shared library provided as a resource. The source code is also supplied. Please note that reading will block when random data is not available. Use only where the highest quality random data is required and possible delays are acceptable.
Author:
AO Industries, Inc.
See Also:
  • Field Details

    • DEV_RANDOM_PATH

      public static final String DEV_RANDOM_PATH
      The device file path used to obtain and add random data.
      See Also:
    • devRandomUF

      public static final PosixFile devRandomUF
      The device file used to obtain and add random data.
    • ENTROPY_AVAIL_PATH

      public static final String ENTROPY_AVAIL_PATH
      The device file path used to obtain the entropy statistics.
      See Also:
    • entropyAvailUF

      public static final PosixFile entropyAvailUF
      The device file used to obtain the entropy statistics.
    • POOL_SIZE_PATH

      public static final String POOL_SIZE_PATH
      The device file path used to obtain the pool size.
      See Also:
    • poolSizeUF

      public static final PosixFile poolSizeUF
      The device file used to obtain the pool size.
  • Constructor Details

    • DevRandom

      public DevRandom()
  • Method Details

    • openDevRandomIn

      public static FileInputStream openDevRandomIn() throws IOException
      Opens the FileInputStream that reads from /dev/random.
      Throws:
      IOException
    • closeDevRandomIn

      public static void closeDevRandomIn() throws IOException
      Closes the FileInputStream that reads from /dev/random.
      Throws:
      IOException
    • getEntropyAvail

      public static int getEntropyAvail() throws IOException
      Gets the number of random bits currently available in the kernel.
      Throws:
      IOException
    • getPoolSize

      public static int getPoolSize() throws IOException
      Gets the number of bits in the random pool in the kernel.
      Throws:
      IOException
    • addEntropy

      public static void addEntropy(byte[] randomData) throws IOException
      Adds random entropy to the kernel.
      Throws:
      IOException
    • setSeed

      public void setSeed(long seed)
      This class does not use this seed value.
      Overrides:
      setSeed in class Random
    • next

      protected int next(int bits)
      Overrides:
      next in class Random
    • nextBoolean

      public boolean nextBoolean()
      Overrides:
      nextBoolean in class Random
    • nextBytes

      public void nextBytes(byte[] bytes)
      Overrides:
      nextBytes in class Random
    • nextBytes

      public void nextBytes(byte[] bytes, int off, int len)
    • nextBytesStatic

      public static void nextBytesStatic(byte[] bytes)
      Static implementation of nextBytes(byte[]).
    • nextBytesStatic

      public static void nextBytesStatic(byte[] bytes, int off, int len)
      Static implementation of nextBytes(byte[], int, int).
    • nextInt

      public int nextInt()
      Overrides:
      nextInt in class Random
    • nextLong

      public long nextLong()
      Overrides:
      nextLong in class Random
    • main

      public static void main(String[] args)
      Manually adds entropy to the kernel, reads from standard in.