Closed OlivierSohn closed 6 years ago
Also, closes #63
@Shimuuar by any chance, did you have the time to look at this PR?
I didn't sorry. Hopefully I'll do it this week
I finally got to review of patch. This is indeed a bug and change have low impact. By default generator is initiialized with fixed carry 362436 < aa
so any subsequent carry will be less than aa
. So I will merge it.
One thing. aa = 1540315826
and 1540315826 ≠ 0x303EEE84
. Where did you get that number. Still
your proof holds irrespective of value of aa
Thanks for catching this!
Good catch, I think I took the other value from the "non complementary" version of mwc256, here : https://github.com/bos/mwc-random/issues/33, because at the time I was also investigating differences between the 2 algorithms, and trying to understand which of the 2 was implemented here (btw, I think here it is the complementary version that is implemented after all)
I'll update the comments to use the right hexa which is 0x5BCF5AB2
.
The comments are fixed now!
Actually proof could be simplified and generalized to arbitrary aa
. Let b = 2^32, a < b and c < a. Then for every q :: Word32 c' < a
therefore ax + c / b < a
Right, this is a more general formulation.
Do you mean we should update the comments?
In the code, I liked having actual numbers because IMO it makes it easier to follow the reasonning.
As you wish.
I plan to merge this commit, cherry pick optimizations from #66, and make 0.14 release tomorrow.
Ok, I'll add a commit to mention that the proof holds for any Word32 aa, but keep the rest as it is now.
@Shimuuar is it ok for you? I'll close #66 once you cherry picked what you needed from it.
Rebased and merged! Sorry for delay. I'll need to update documentation as well I think. Also please keep #66 open for a while
…han the multiplicator : force the carry value to be smaller than the multiplicator by using modulo.
Makes the implementation conform to the algorithm as described here.
Might be seen as a breaking change for users specifying out-of-range values for the carry, because they will get different results than before.