[
https://issues.apache.org/jira/browse/MATH-1322?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15139272#comment-15139272
]
Gilles commented on MATH-1322:
------------------------------
bq. After applying patch, "93740670" is displayed. Same value.
What worries me (even as your patch is applied) is that the same seed (namely
-1) results in different states, whether it happens to be cast to an "int":
{code}
rng.setSeed((int) -1);
int n = rng.nextInt(); // n == 419326371
{code}
or cast to a "long":
{code}
rng.setSeed((long) -1);
int n = rng.nextInt(); // n == 93740670
{code}
Do you see what I mean?
This is one of the (IMO) deficiencies which issue MATH-1319 aims at making
disappear (by defining a _unique_ way to set the seed).
In this case, IIUC, the problem is having overloaded {{setSeed}} to take an
{{int}} argument although to be faithful to the original code, it must be
interpreted as the low-order bits of a {{long}}.
Since the principle of specifying a seed is intended for reproducing a
sequence, bluntly changing the code is not an option.
I'd rather imagine that {{setSeed(int)}} must be deprecated, and a conversion
method must be provided so that {{setSeed(convertToLong((int) seed))}} results
in the same state as the current {{setSeed((int) seed)}}.
> Negative integer seed for MersenneTwister is not working.
> ---------------------------------------------------------
>
> Key: MATH-1322
> URL: https://issues.apache.org/jira/browse/MATH-1322
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.6
> Reporter: Morikawa Joe
> Labels: patch
> Attachments: MersenneTwister.patch
>
>
> MersenneTwister.setSeed(int seed) has a bug.
> If seed is negative, longMT also becomes negative.
> First 32 bits are filled by 0xFFFFFFFF.
> But it should be positive. First 32 bits should be filled by 0x00000000.
> Ex) Integer -1 is 0xffffffff.
> Long -1 is 0xffffffffffffffff.
> Long 0xffffffff is 4294967295.
> I created simple patch.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)