Class MultiplyWithCarry256

All Implemented Interfaces:
RandomIntSource, RestorableUniformRandomProvider, UniformRandomProvider

public class MultiplyWithCarry256 extends IntProvider
Port from Marsaglia's "Multiply-With-Carry" algorithm.

Implementation is based on the (non-portable!) C code reproduced on that page.

Since:
1.0
See Also:
  • Field Details

    • Q_SIZE

      private static final int Q_SIZE
      Length of the state array.
      See Also:
    • SEED_SIZE

      private static final int SEED_SIZE
      Size of the seed.
      See Also:
    • A

      private static final long A
      Multiply.
      See Also:
    • state

      private final int[] state
      State.
    • index

      private int index
      Current index in "state" array.
    • carry

      private int carry
      Carry.
  • Constructor Details

    • MultiplyWithCarry256

      public MultiplyWithCarry256(int[] seed)
      Creates a new instance.
      Parameters:
      seed - Seed. If the length is larger than 257, only the first 257 elements will be used; if smaller, the remaining elements will be automatically set.
  • Method Details