← Back to index
|
Original Bugzilla link
Bug 17832 – std.random.choice cannot be used with other random generators
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-09-17T07:15:08Z
Last change time
2018-01-28T10:36:48Z
Keywords
pull
Assigned to
No Owner
Creator
Anton Fediushin
Comments
Comment #0
by fediushin.anton — 2017-09-17T07:15:08Z
This code: ``` auto arr = [1,2,3]; choice(arr); auto rng = Random(); choice(arr, rng); auto rng2 = Xorshift(); choice(arr, rng2); ``` Fails on the last line with: /usr/include/dlang/dmd/std/random.d(2002): Error: cannot implicitly convert expression rndGen() of type MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) to XorshiftEngine!(uint, 128u, 11u, 8u, 19u) randomissue.d(11): Error: template instance std.random.choice!(int[], XorshiftEngine!(uint, 128u, 11u, 8u, 19u)) error instantiating
Comment #1
by greensunny12 — 2018-01-28T01:05:00Z
PR:
https://github.com/dlang/phobos/pull/5741
Comment #2
by github-bugzilla — 2018-01-28T10:36:47Z
Commits pushed to master at
https://github.com/dlang/phobos
https://github.com/dlang/phobos/commit/db5c1c84b9b344c28214463f7c94f83580363ded
Addresses Issue 17832 Random choice default argument was deciding the type of the template. I'm not sure if this is a deeper bug, but it can easily be fixed with this patch which simply overloads the function. Also added a unittest which would have failed under the old code.
https://github.com/dlang/phobos/commit/7823e1181d0a7e4698b77c7ba5fbbb25dcdebc7e
Merge pull request #5741 from dunkyp/issue_17832 Fix Issue 17832 - std.random.choice cannot be used with other random generators