[
https://issues.apache.org/jira/browse/RNG-200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18107072#comment-18107072
]
Alex Herbert edited comment on RNG-200 at 8/23/26 3:30 PM:
-----------------------------------------------------------
On further investigation, the JDKRandomBridge has a constructor that does not
support additional arguments for the RandomSource:
{code:java}
/**
* Creates a new instance.
*
* @param source Source of randomness.
* @param seed Seed. Can be {@code null}.
*/
public JDKRandomBridge(RandomSource source,
Object seed) {
this.source = source;
delegate = source.create(seed);
// ...
}
{code}
Thus when TWO_CMRES_SELECT is used it throws an IllegalArgumentException in the
JDKRandomBridge constructor.
To fully support TWO_CMRES_SELECT would require a new constructor for the
JDKRandomBridge so that additional arguments can be passed to the RandomSource
constructor.
Since this detail has not been observed in 10 years since the library inception
the simple option is to document that TWO_CMRES_SELECT is not supported.
was (Author: alexherbert):
On further investigation, the JDKRandomBridge has a constructor that does not
support additional arguments for the RandomSource:
{code:java}
/**
* Creates a new instance.
*
* @param source Source of randomness.
* @param seed Seed. Can be {@code null}.
*/
public JDKRandomBridge(RandomSource source,
Object seed) {
this.source = source;
delegate = source.create(seed);
// ...
}
{code}
Thus when TWO_CMRES_SELECT is used it defaults to sub-cycle generators 0 and 1
and is the same as TWO_CMRES.
To fully support TWO_CMRES_SELECT would require a new constructor for the
JDKRandomBridge so that additional arguments can be passed to the RandomSource
constructor.
Since this detail has not been observed in 10 years since the library inception
the simple option is to document that TWO_CMRES_SELECT is not supported and
throw an exception from the JDKRandomBridge constructor.
> TWO_CMRES_SELECT cannot be serialized within JDKRandomBridge
> ------------------------------------------------------------
>
> Key: RNG-200
> URL: https://issues.apache.org/jira/browse/RNG-200
> Project: Commons RNG
> Issue Type: Bug
> Components: simple
> Affects Versions: 1.7
> Reporter: Alex Herbert
> Assignee: Alex Herbert
> Priority: Minor
> Fix For: 1.8
>
>
> The TWO_CMRES_SELECT random source is constructed using a seed and two chosen
> sub-cycle generators. The state of the RNG can be saved and restored using
> the methods of RestorableUniformRandomProvider. This state *does not* include
> the identifiers of the sub-cycle generators. Thus the state can be restored
> to the *same instance* of the RNG where the sub-cycle generators are known.
> It cannot be used to create a new instance of the generator when
> deserializing the state in the JDKRandomBridge.
> The JDKRandomBridge creates a new instance of the random source using:
> {code:java}
> delegate = source.create(); {code}
> This is the no argument factory method of RandomSource:
> {code:java}
> public RestorableUniformRandomProvider create() {code}
> The TWO_CMRES_SELECT generator requires the two sub cycle generators to be
> specified in the overloaded factory method:
> {code:java}
> public RestorableUniformRandomProvider create(Object seed,
> Object... data) {code}
> For example:
> {code:java}
> long seed = 1;
> int subCycle1 = 3;
> int subCycle2 = 8;
> delegate = source.create(seed, subCycle1, subCycle2); {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)