[
https://issues.apache.org/jira/browse/RNG-169?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17508460#comment-17508460
]
Alex Herbert commented on RNG-169:
----------------------------------
I have pushed an update to master containing the change to use a consistent
seed expansion approach. When an input seed must be enlarged then all methods
use a SplitMix64 style generator to provide the additional bytes.
Other changes are to move all conversion methods to the new package level
Conversions class. All conversions are performed by static methods with the
minimum memory allocation (i.e. no large intermediate arrays).
A summary of the behavioural changes has been added to the changes log and will
be in the release notes. These are listed below:
* Creation using byte[], long or the native seed type is unchanged
* Creation using int[] and long[] seeds that are converted to another native
type has changed. Bytes are now interpreted as little endian. The effect is
that the same bytes stored in a byte[] (little-endian) or an int[] can be used
to create a RNG with a long[] native seed.
* Creation of a RNG with a long native seed from an int[] will provide a
possible 2^64 seeds fixing a bug that previously only provided 2^32 possible
seeds for the 64-bit long. This will affect 8 generators in the library (listed
in a posting above).
* All seed conversions that expand the seed size will use the same generation
method to provide additional bytes. For example creating a RNG with a long[]
native seed with either an int (123) or a long (123L) will create the same RNG.
As before RNG sequence output is ensured to be reproducible within the same
release version.
RNG sequence output will change when updating to version 1.5 if using int[],
long[] or int seeds to construct generators with a different native seed type.
This is most likely to effect for example unit tests creating a fixed generator
with an integer seed:
{code:java}
UniformRandomProvider rng = RandomSource.KISS.create(12345);
{code}
> Update array seed conversion to use optimum seed length
> -------------------------------------------------------
>
> Key: RNG-169
> URL: https://issues.apache.org/jira/browse/RNG-169
> Project: Commons RNG
> Issue Type: Improvement
> Components: simple
> Affects Versions: 1.4
> Reporter: Alex Herbert
> Priority: Trivial
> Fix For: 1.5
>
>
> The seed conversion routines in ByteArray2LongArray and ByteArray2IntArray
> can be optimised for memory usage.
> The converters can be updated to implement Seed2ArrayConverter. This allows
> the length of the output seed to be constructed to the correct length. This
> will avoid converting part of the byte[] seed that is not used.
> In addition the input seed is expanded if it is not modulus 8 or 4
> respectively using Arrays.copyOf. This will zero fill the end of the seed.
> The array can then be converted by the NumberFactory without an exception.
> These routines should be updated to use the same method as NumberFactory to
> fill in a long[] and then add any trailing bytes to the final long.
> This avoids any array copy when using arbitrary seed lengths, e.g.
> SecureRandom.getSeed(13).
--
This message was sent by Atlassian Jira
(v8.20.1#820001)