Bug 7936 – std.random.randomSample always returns the same first value when passed a random number generator

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-17T21:14:00Z
Last change time
2012-07-20T07:07:26Z
Assigned to
nobody
Creator
joseph.wakeling

Attachments

IDFilenameSummaryContent-TypeSize
1097sample.dMinimal example demonstrating the issue. Outputs 4 random samples, the latter 3 of which have all been differently seeded.text/x-dsrc550

Comments

Comment #0 by joseph.wakeling — 2012-04-17T21:14:53Z
Created attachment 1097 Minimal example demonstrating the issue. Outputs 4 random samples, the latter 3 of which have all been differently seeded. If randomSample is passed a user-defined random number generator, e.g. auto urng = Random(unpredictableSeed); auto s = randomSample(iota(0, 100), 5, urng); ... then the first value of the sample will always be identical (for a given RNG type), regardless of how the RNG is seeded. As an example, try the attached code. The 3 seeded cases all have a first value of 21 on my system. This error is occurring with the latest Phobos from GitHub.
Comment #1 by lovelydear — 2012-04-19T05:59:05Z
Comment #2 by joseph.wakeling — 2012-07-20T07:07:26Z
With the merging of pull request 553 this bug has now been fixed: https://github.com/D-Programming-Language/phobos/pull/553