Alex Herbert created RNG-174:
--------------------------------

             Summary: Improve support for non-zero seeds
                 Key: RNG-174
                 URL: https://issues.apache.org/jira/browse/RNG-174
             Project: Commons RNG
          Issue Type: Improvement
          Components: simple
    Affects Versions: 1.4
            Reporter: Alex Herbert
            Assignee: Alex Herbert
             Fix For: 1.5


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:
{code:java}
byte[] createSeed();
byte[] createSeed(UniformRandomProvider rng);

static int[] createIntArray(int n);
static long[] createLongArray(int n);{code}
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:
{code:java}
RestorableUniformRandomProvider create(); {code}
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:
{code:java}
int[] RandomSource.createIntArray(int n, int from, int to);
long[] RandomSource.createLongArray(int n, int from, int to);
{code}
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.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to