Class RndAdapter

java.lang.Object
java.util.Random
io.github.olyutorskii.aletojio.rng.RndAdapter
All Implemented Interfaces:
RndInt31, RndInt32, RndInt64, Serializable

public class RndAdapter extends Random implements RndInt32, RndInt64, RndInt31
Random generator exchange adapter.

Designed to conserve as much random source entropy as possible.

Entropy is consumed first from MSB.

512 bits buffer is provided.

TODO: supporting java.util.random.RandomGenerator (JDK17 or later) and org.apache.commons.rng.UniformRandomProvider

See Also:
  • Constructor Details

  • Method Details

    • setSeed

      public void setSeed(long seed) throws UnsupportedOperationException
      Seed change is not supported.

      * However, it is allowed only during the initial constructor.

      Overrides:
      setSeed in class Random
      Parameters:
      seed - not supported
      Throws:
      UnsupportedOperationException - always
    • nextBit

      public boolean nextBit()
      Return next random number as 1bit boolean.

      Unlike Random.nextBoolean() implement, any entropy from random source is not discarded.

      Returns:
      random number
    • nextByte

      public byte nextByte()
      Return next random number as 8bit byte.

      Unlike Random.nextBytes(byte[]) implement, any entropy from random source is not discarded.

      Returns:
      random number
    • nextInt31

      public int nextInt31()
      Return next random number as 31bit int from LSB without sign-bit.

      Only positive or zero value returned.

      * LCG implementations on CPU without 64-bit remainders often output only 31-bit random numbers.

      Entropy obtained from random source is returned without entropy missing.

      Specified by:
      nextInt31 in interface RndInt31
      Returns:
      random number
    • nextInt32

      public int nextInt32()
      Return next random number as 32bit int with random sign-bit.

      Entropy obtained from random source is returned without entropy missing.

      Specified by:
      nextInt32 in interface RndInt32
      Returns:
      random number
    • nextInt64

      public long nextInt64()
      Return next random number as 64bit long with random sign-bit.

      Entropy obtained from random source is returned without entropy missing.

      Specified by:
      nextInt64 in interface RndInt64
      Returns:
      random number
    • next

      protected int next(int bits)
      Generates the next pseudorandom number. Subclasses should override this, as this is used by Random original implementations.

      * The original Random implementation often discards higher or lower bits of this return value.

      Entropy obtained from random source is returned without entropy missing.

      Overrides:
      next in class Random
      Parameters:
      bits -
      Returns: