Commit graph

190 commits

Author SHA1 Message Date
Ilya Yaroshenko
2c744b54e1 std.range: constraints => primitives
See discussion and voting in #2661
2014-11-23 20:05:20 +03:00
H. S. Teoh
97c2f565bc Merge pull request #2754 from 9il/random
std.random: update imports
2014-11-21 14:41:04 -08:00
Ilya Yaroshenko
ef94b26162 std.random: update imports 2014-11-21 00:18:06 +03:00
Lars T. Kyllingstad
96583fe46b isNaN() is not a property
...so it shouldn't be used as one.
2014-11-20 20:22:00 +01:00
Andrei Alexandrescu
68beb7c515 Merge pull request #2613 from braddr/safe
mark most of std.algorithm's unit tests as @safe
2014-10-19 10:29:32 -07:00
Martin Nowak
c855945f46 Merge pull request #2614 from Geod24/fix-license-doc
[DDOC] Usage of WEB macro for License everywhere
2014-10-17 00:16:49 +02:00
Geod24
0fb95b8c27 Usage of WEB macro for License everywhere 2014-10-15 11:30:42 +02:00
Joakim
093d636de4 Deprecate std.c.* and move all remaining declarations to core.stdc.* 2014-10-14 09:26:21 -05:00
Brad Roberts
4e66cda63c uniform should be @safe 2014-10-13 00:09:18 -07:00
Brad Roberts
f70e1e41e4 Fix unpredictableSeed so that rndstuff can be used in @safe code
Allows:
1) canFind's tests to be @safe
2) allows the remainder of find's tests to be @safe
2014-10-13 00:04:37 -07:00
H. S. Teoh
4a6890fc40 Preemptive fix of other places where .sort is used 2014-09-28 08:04:52 -07:00
Tero Hänninen
2743f9b8fe Simplify partialShuffle 2014-08-15 21:54:03 +03:00
H. S. Teoh
3e02fb7772 Fix missing $(RPAREN) in ddoc for std.random.uniform01. 2014-08-08 15:43:30 -07:00
Joseph Rushton Wakeling
88d86ecda0 Fix Issue #12835: open lower bound for integral-type uniform()
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.
2014-07-11 23:10:18 +02:00
AndrewEdwards
7295c7196d Update random.d
Fix Ddoc: Stray ")" warning.
2014-06-29 17:13:15 +09:00
Joseph Rushton Wakeling
cb5ee35ad6 Fix Issue #12877: allow uniform() to handle dchar variates
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.
2014-06-08 18:58:13 +02:00
monarch dodra
abcf061a93 Merge pull request #2051 from tom-tan/safe-pure-nothrow-std-random-generators
Mark methods for random number generators in std.random as safe pure not...
2014-04-05 23:32:46 +02:00
Tomoya Tanjo
e520962982 Mark LinearCongruentialEngine.front and XorshiftEngine.front as const 2014-04-04 11:34:37 +09:00
Joseph Rushton Wakeling
93fe844b72 Small optimization to uniform01
Only need to chech u < 1 if RNG returns non-integral variates.
2014-03-27 21:18:40 +01:00
Tomoya Tanjo
412ec99bea Mark methods for random number generators in std.random as safe pure nothrow 2014-03-26 20:19:11 +09:00
Joseph Rushton Wakeling
d0727dc7a0 Fix Issue #5240: faster std.random.uniform for [0.0, 1.0) range
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
2014-03-25 21:09:41 +01:00
Marc Schütz
90262dcffc Remove another use of the comma operator 2014-03-23 15:51:31 +01:00
Daniel Murphy
4d0892baba Remove uses of the comma operator 2014-02-18 00:48:40 +11:00
Peter Alexander
26eecf4651 Fix Issue 4417 - isUniformRNG constraints for std.random.uniform
https://d.puremagic.com/issues/show_bug.cgi?id=4417
2014-02-15 20:55:56 +00:00
Andrej Mitrovic
749143754a Add uniform example for enums. 2014-02-13 08:18:54 +01:00
k-hara
b391b2ec9f Convert to new alias syntax 2014-02-11 15:27:05 +09:00
Dmitry Olshansky
71f9550eac Merge pull request #1874 from monarchdodra/11960
Fix Issue 11960 - Phobos Mersenne Random Engine not supporting unsigned longs
2014-01-30 11:45:23 -08:00
monarch dodra
fc5ff02eb9 Add an MT unittest 2014-01-22 16:42:49 +01:00
monarch dodra
06e9874060 Fix Issue 11960 - Phobos Mersenne Random Engin...
...e not supporting unsigned longs
2014-01-22 15:11:43 +01:00
monarch dodra
edaad18d00 Document the rest of the parameters 2014-01-22 15:10:04 +01:00
monarch dodra
ffcae1609d Add extra asserts on "w" 2014-01-22 15:08:50 +01:00
monarch dodra
cba9da3835 Move static asserts
So they trigger before they create a compile error
2014-01-22 14:56:12 +01:00
monarch dodra
f680ea030f MT alignement 2014-01-22 14:55:13 +01:00
Daniel Murphy
a656f26e9e Remove use of automatic adjacent string literal concatenation from phobos 2014-01-20 03:42:21 +11:00
monarch dodra
fc48d56284 Merge pull request #1717 from Zshazz/issue_11598
Fix issue 11598 - uniform could be faster for integrals
2013-12-16 05:24:20 -08:00
Joseph Rushton Wakeling
fbc8d1e08e Fix Issue 11738 - partialShuffle should actually _be_ a partial shuffle :-)
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.
2013-12-14 12:12:33 +01:00
Chris Cain
62f058f11c Fixed trailing whitespace 2013-12-03 07:19:27 -05:00
Chris Cain
3e63ce8a0f Remove special-case check on rare condition
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.
2013-12-03 07:16:26 -05:00
Chris Cain
18b8716ff2 Include algorithm documentation for integral uniform 2013-12-02 04:07:05 -05:00
Chris Cain
7c01f661ca Fix formatting issues 2013-12-02 03:58:16 -05:00
Chris Cain
30ced820e5 Fix issue 11598 - uniform could be faster for integrals
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.
2013-11-24 23:04:57 -05:00
k-hara
aead6721a6 fix property enforcement 2013-09-28 14:46:44 +09:00
Joseph Rushton Wakeling
ce8155c7ad Fix Issue 10322 - ensure RandomSample is initialized before use
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.
2013-09-26 16:53:50 +02:00
Joseph Rushton Wakeling
3bdda604a8 Slightly tone down warning message about value-type RNGs and Random{Cover, Sample}. 2013-08-26 10:51:54 +02:00
Joseph Rushton Wakeling
98a3efb621 Restore Random{Cover, Sample} constructors accepting value-type RNG. 2013-08-26 10:51:54 +02:00
Joseph Rushton Wakeling
691efb167d Make sure RNGs are passed to Random{Cover, Sample} by ref/auto ref. 2013-08-26 10:51:53 +02:00
Joseph Rushton Wakeling
40ee13749f Ensure bool[] _chosen is filled with false at start of cover. 2013-08-26 10:51:53 +02:00
Joseph Rushton Wakeling
c000b794a6 Small stylistic tweaks for Andrei :-) 2013-08-26 10:51:53 +02:00
Joseph Rushton Wakeling
a3ead0ac31 Documentation updates for RandomCover and RandomSample.
Mostly regarding the statistical safety-related concerns
when passing a specified RNG, plus a few corrections.
2013-08-26 10:51:53 +02:00
Joseph Rushton Wakeling
c06ca0ce09 Unittests for RandomCover and RandomSample should test with all RNG types. 2013-08-26 10:51:53 +02:00