← Back to index
|
Original Bugzilla link
Bug 9607 – std.random.randomShuffle and partialShuffle don't work with Xorshift
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-02-27T04:34:00Z
Last change time
2013-07-16T02:32:31Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0
by bearophile_hugs — 2013-02-27T04:34:45Z
import std.random: randomShuffle, rndGen, Mt19937, Xorshift, partialShuffle; void main() { int[] items = [10, 20, 30]; randomShuffle(items); // OK randomShuffle(items, rndGen); // OK Mt19937 gen; randomShuffle(items, gen); // OK Xorshift rng; randomShuffle(items, rng); // Error. partialShuffle(items, 2, rng); // Error. } DMD 2.063alpha gives: ...\dmd2\src\phobos\std\random.d(1346): Error: constructor std.random.XorshiftEngine!(uint, 128, 11, 8, 19).XorshiftEngine.this (uint x0) is not callable using argument types (MersenneTwisterEngine!(uint, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18)) ...\dmd2\src\phobos\std\random.d(1346): Error: cannot implicitly convert expression (rndGen()) of type MersenneTwisterEngine!(uint, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18) to uint ...\dmd2\src\phobos\std\random.d(1376): Error: constructor std.random.XorshiftEngine!(uint, 128, 11, 8, 19).XorshiftEngine.this (uint x0) is not callable using argument types (MersenneTwisterEngine!(uint, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18)) ...\dmd2\src\phobos\std\random.d(1376): Error: cannot implicitly convert expression (rndGen()) of type MersenneTwisterEngine!(uint, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18) to uint ...\dmd2\src\phobos\std\random.d(1349): Error: template instance std.random.partialShuffle!(int[], XorshiftEngine!(uint, 128, 11, 8, 19)) error instantiating temp3.d(10): instantiated from here: randomShuffle!(int[], XorshiftEngine!(uint, 128, 11, 8, 19)) temp3.d(10): Error: template instance std.random.randomShuffle!(int[], XorshiftEngine!(uint, 128, 11, 8, 19)) error instantiating
Comment #1
by joseph.wakeling — 2013-06-21T07:10:47Z
It's an instance of Issue #2803. I have a fix ready for this particular case -- will submit a pull request soon.
Comment #2
by joseph.wakeling — 2013-06-22T02:03:34Z
(In reply to comment #1) > It's an instance of Issue #2803. I have a fix ready for this particular case > -- will submit a pull request soon.
https://github.com/D-Programming-Language/phobos/pull/1362
Comment #3
by github-bugzilla — 2013-07-15T15:16:10Z
Commits pushed to master at
https://github.com/D-Programming-Language/phobos
https://github.com/D-Programming-Language/phobos/commit/e86bc65639036d240d5ec6ce0254ccebee097943
Fix Issue 9607 - std.random.randomShuffle() and partialShuffle() don't work with Xorshift. This is an instance of Issue 2803, a clash between a template parameter and a default argument. I've used the workaround proposed in that issue thread:
http://d.puremagic.com/issues/show_bug.cgi?id=2803#c1
Tests have been included to ensure that these functions work with all possible RNG types.
https://github.com/D-Programming-Language/phobos/commit/443b54e30b4b67b8968ecde51dcae66c855c135b
Merge pull request #1362 from WebDrake/randomshuffle Fix Issue 9607 - std.random.randomShuffle() and partialShuffle() don't work with Xorshift.
Comment #4
by joseph.wakeling — 2013-07-16T02:32:31Z
*** Issue 7863 has been marked as a duplicate of this issue. ***