Class MarsagliaTsangWangDiscreteSampler.MarsagliaTsangWangBase64Int16DiscreteSampler

java.lang.Object
org.apache.commons.rng.sampling.distribution.MarsagliaTsangWangDiscreteSampler.AbstractMarsagliaTsangWangDiscreteSampler
org.apache.commons.rng.sampling.distribution.MarsagliaTsangWangDiscreteSampler.MarsagliaTsangWangBase64Int16DiscreteSampler
All Implemented Interfaces:
DiscreteSampler, SharedStateDiscreteSampler, SharedStateSampler<SharedStateDiscreteSampler>
Enclosing class:
MarsagliaTsangWangDiscreteSampler

private static class MarsagliaTsangWangDiscreteSampler.MarsagliaTsangWangBase64Int16DiscreteSampler extends MarsagliaTsangWangDiscreteSampler.AbstractMarsagliaTsangWangDiscreteSampler
An implementation for the sample algorithm based on the decomposition of the index in the range [0,2^30) into 5 base-64 digits with 16-bit backing storage.
  • Field Details

    • MASK

      private static final int MASK
      The mask to convert a byte to an unsigned 16-bit integer.
      See Also:
    • t1

      private final int t1
      Limit for look-up table 1.
    • t2

      private final int t2
      Limit for look-up table 2.
    • t3

      private final int t3
      Limit for look-up table 3.
    • t4

      private final int t4
      Limit for look-up table 4.
    • table1

      private final short[] table1
      Look-up table table1.
    • table2

      private final short[] table2
      Look-up table table2.
    • table3

      private final short[] table3
      Look-up table table3.
    • table4

      private final short[] table4
      Look-up table table4.
    • table5

      private final short[] table5
      Look-up table table5.
  • Constructor Details

    • MarsagliaTsangWangBase64Int16DiscreteSampler

      MarsagliaTsangWangBase64Int16DiscreteSampler(UniformRandomProvider rng, String distributionName, int[] prob, int offset)
      Parameters:
      rng - Generator of uniformly distributed random numbers.
      distributionName - Distribution name.
      prob - The probabilities.
      offset - The offset (must be positive).
    • MarsagliaTsangWangBase64Int16DiscreteSampler

      private MarsagliaTsangWangBase64Int16DiscreteSampler(UniformRandomProvider rng, MarsagliaTsangWangDiscreteSampler.MarsagliaTsangWangBase64Int16DiscreteSampler source)
      Parameters:
      rng - Generator of uniformly distributed random numbers.
      source - Source to copy.
  • Method Details

    • fill

      private static int fill(short[] table, int from, int to, short value)
      Fill the table with the value.
      Parameters:
      table - Table.
      from - Lower bound index (inclusive)
      to - Upper bound index (exclusive)
      value - Value.
      Returns:
      the upper bound index
    • sample

      public int sample()
      Description copied from interface: DiscreteSampler
      Creates an int sample.
      Returns:
      a sample.
    • withUniformRandomProvider

      public SharedStateDiscreteSampler withUniformRandomProvider(UniformRandomProvider rng)
      Description copied from interface: SharedStateSampler
      Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.
      Parameters:
      rng - Generator of uniformly distributed random numbers.
      Returns:
      the sampler