The existing docs have not been tweaked in any way, so the new additions
result in some duplication of information. This seems a better first
step than a more major revision.
Documentation for struct methods has been left unchanged, and will be
addressed in a later patch.
I've also left the documentation for uniformDistribution unchanged as
IMHO this function is so broken in its design, it really ought to be
deprecated and removed :-)
Added a cast to ensure the setting of lower bound can handle character
types and integral types smaller than int. The additional unittests
should prevent such issues from arising again.
Since [dchar.min, dchar.max] does not cover the full bit range of dchar,
optimizations that work for other integral types will fail here, and
result in illegal unicode points being generated.
This fix avoids breaking any existing calls to uniform() via a twofold
approach:
* uniform!"[]"(T.min, T.max) will only call uniform!ResultType if
T is not a dchar;
* uniform!dchar will not try and use the entire bit range but will
instead call uniform!"[]"(dchar.min, dchar.max).
Unittests have been added that should prevent such issues from arising
again.
Following typical design in other languages, the function is named
uniform01. It can be templated on floating-point type, defaulting
to double if none is specified.
The implementation is pretty much derived from its counterpart in
Boost.Random, in particular in its taking account of the different
requirements for integral versus floating-point RNG values, and in
checking that the generated variate is less than 1 before returning.
This last check is necessary simply because we can't guarantee, in
the case of a floating-point based RNG, that we will not get a
result exactly equal to 1.
Fixes http://d.puremagic.com/issues/show_bug.cgi?id=5240
This patch fixes the problem that partialShuffle was in fact invariably
shuffling the whole of the input, undetected because there were unittests
only for randomShuffle.
As well as the fix I've added some unittests specifically for partialShuffle
to ensure that it works properly, and I've taken the opportunity to tweak a
couple of bits of Ddoc and tidy up the randomShuffle unittests.
A special case was checked that only occurs when calling uniform with a range of only one element. This was not necessary to keep the math correct and represented a slight slowdown in the common case for no apparent benefit.
These changes retain the uniform quality of this function while, in the
common case, cutting the number of division operations in half.
Additionally, extra unittests were added to assure that all of the
bounds were tested properly.
This patch fixes a problem where the public methods .index()
or .popFront() might be called without the first value of the
sample having been determined, which would then cause spurious
results. The runtime initialization check currently performed
in .front has been extended to those methods.
The private boolean checks in the previous implementation have
been replaced with an enum indicating the algorithm to be used
(A, D or None) with None indicating that the sample has not
been initialized.
Step D1 of Algorithm D has been moved to the skip() function,
which results in a significant performance boost.
Unittests have been introduced to cover the cases where .index
or .popFront() are called before .front.
Finally, the .index method has been made a @property, which I
take to be an oversight of the original code.