Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-174

Improve support for non-zero seeds

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 1.4
    • 1.5
    • simple
    • None
    • Easy

    Description

      The default seed arrays created by RandomSource are ensured to be non-zero in the first position. This is to support xor-based generators which are non-functional when seeded with all zeros.

      All xor-based generators in the library fill their state from position 0 in the input seed array. So this has worked for all current implementations.

      The new LXM family of generators have a composite seed of the state of a linear congruential generator (LCG) and the state of a xor-based generator (XBG). Ideal seeding for these generators places the LCG state first. This is due to the behaviour of the LXM family where the seeding of the LCG can create independent streams of RNG output, specifically when using a different LCG add parameter (which must be odd). Thus seeding with values 1, 3, 5, 7, which are then expanded into a full array, will create non-overlapping RNG sequences.

      The requirement to place the LCG state first in the seed shifts the seed for the XBG state. It is possible that a generated seed would be all zero in the XBG state. The current seed generator is 16-equidistributed and can thus output consecutive zeros. The RandomSource seeding behaviour should be updated with the option to create a seed which is non-zero in a specified range of the seed array.

      The public API in RandomSource is:

      byte[] createSeed();
      byte[] createSeed(UniformRandomProvider rng);
      
      static int[] createIntArray(int n);
      static long[] createLongArray(int n);

      The createSeed methods are specific to each RandomSource instance. This is delegated to an internal package which creates a native seed of the correct length and converts it to bytes. No changes to the public API should be required to support non-zero seeds in a range.

      Note that the seed generation method is also used by:

      RestorableUniformRandomProvider create(); 

      So any LXM generator created by the RandomSource enum with no explicit seed will also obtain this functionality.

      For the array generation methods, these have no documentation on the non-zero behaviour. Either these methods can be left alone, or updated to add a range:

      int[] RandomSource.createIntArray(int n, int from, int to);
      long[] RandomSource.createLongArray(int n, int from, int to);
      

      In the interest of simplicity, and given that createSeed() is the preferred method for a known RandomSource, additional overloads of these methods can be omitted.

      Attachments

        Issue Links

          Activity

            People

              aherbert Alex Herbert
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: