Created attachment 867
Patch for this suggestion
rndGen always returns Random(usually MT) object. This is often useful, but
randomShuffle cant't take other random generators.
I think following signature is better.
ref RandomGen rndGen(RandomGen = Random)()
But this change forces us to write parenthesis function call.
rndGen; // Compilation error
rndGen(); // OK, return Random object.
For me, this is no problem. However I don't know the writing style of other
people.
Comment #1 by smjg — 2012-04-08T15:33:08Z
(In reply to comment #0)
> Created an attachment (id=867) [details]
> Patch for this suggestion
>
> rndGen always returns Random(usually MT) object. This is often useful, but
> randomShuffle cant't take other random generators.
It can, as of DMD 2.058 at least. Its signature is
void randomShuffle(Range, RandomGen = Random)(Range r,
ref RandomGen gen = rndGen)
The two parameters are the range to shuffle and the RNG to use to perform the shuffle.
> I think following signature is better.
>
> ref RandomGen rndGen(RandomGen = Random)()
What, exactly, would your rndGen function _do_ to the RandomGen object you pass into it???
Comment #2 by bearophile_hugs — 2012-04-08T16:43:35Z
See also Issue 4851
Comment #3 by joseph.wakeling — 2013-05-03T07:38:00Z
rndGen _should_ always return Random, because rndGen is intended to provide a thread-safe instance of the default RNG type (which _is_ Random).
The problems identified here aren't with rndGen but with code that does not take into account RNG instances other than rndGen. So, I suggest this bug be marked as invalid.