Bug 16724 – RandomCover.popFront is a no-op for the first call
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-11-23T02:36:00Z
Last change time
2017-02-11T00:54:05Z
Keywords
pull
Assigned to
razvan.nitu1305
Creator
dlang
Comments
Comment #0 by dlang — 2016-11-23T02:36:12Z
I let the code speak for itself.
import std.random;
import std.range;
import std.algorithm;
void main ()
{
auto range = iota(10);
auto randy = range.randomCover;
//randy.front // uncomment this and the assert works
randy.popFront;
assert(randy.array.length == range.length - 1);
}
Comment #1 by razvan.nitu1305 — 2016-12-19T10:35:34Z
Comment #5 by joseph.wakeling — 2017-02-11T00:54:05Z
Sorry to have missed this, but the fix is itself broken, because it strips out the lazy `front` of `randomCover`.
First, random algorithms (like random cover) ideally need to have a truly lazy initial `front` value, otherwise you can run into trivial errors like:
auto arr = [1, 2, 3, 4, 5];
auto cover = arr.randomCover;
cover.writeln; // three 'different' covers
cover.writeln; // but each of them with
cover.writeln; // the same first value
... so the check on already-chosen elements in `front` wasn't there by accident (although it may have needed further work in how it was implemented).
Second, I just tried running the above right now and got a never-ending stream of `5, 5, 5, 5, 5, ...` out of my computer before I killed it. So I'm not sure that this new randomCover is working right at all :-(