D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8314 - randomSample primes with constant
Summary: randomSample primes with constant
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-27 23:35 UTC by Martin Nowak
Modified: 2013-02-05 13:00 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2012-06-27 23:35:08 UTC
import std.random, std.range, std.stdio;

void main()
{
    foreach (_; 0 .. 100)
    {
        immutable seed = unpredictableSeed();
        writeln(seed, " => ", randomSample(iota(100), 1, Random(seed)).front);
    }
}

--------

The random generator is assigned to the Range only after it was primed and
the default constructed random generator always returns the same first value.
Comment 1 github-bugzilla 2012-07-22 19:50:32 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/aa896e08ccbdb3deee98658f09022bdb4c5dc503
set random generator in constructor

- Bug 8314 was already fixed by adding a _first flag

https://github.com/D-Programming-Language/phobos/commit/92335506d309d4f06e1757b149c5069d02ac1174
Merge pull request #654 from dawgfoto/fix8314

fix issue 8314