[
https://issues.apache.org/jira/browse/RNG-169?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17507677#comment-17507677
]
Alex Herbert commented on RNG-169:
----------------------------------
Further review of the seed conversions show only the following instances of
composed seed conversions:
{noformat}
int
long[] -> long -> int
byte[] -> int[] -> int
long
int[] -> int -> long * loss of bits
byte[] -> long[] -> long
int[]
int -> long -> int[]
long[]
int -> long -> long[]{noformat}
All the other conversions map direct from the source type to the native type.
While the array - > array -> primitive conversions are inefficient they do not
lose seed entropy.
The conversion of the int[] to an int will combine all the bits to 32-bits of
randomness. These are then doubled to a 64-bit length. So the number of
possible seeds from an int[] is 2^32 and not 2^64.
I will have a look at adding convertors for:
{noformat}
byte[] -> int == byte[] -> int[] -> int
byte[] -> long == byte[] -> long[] -> long
int[] -> long == int[] -> long[] -> long * behaviour change{noformat}
Only the int[] -> long converter will introduce a behavioural change to create
a different RNG state. I would consider this a bug in the current
implementation that would be acceptable to change.
> 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)