Commit graph

137 commits

Author SHA1 Message Date
Andrei Alexandrescu
73c8b59bb5 Merge pull request #1412 from Hackerpilot/master
Code cleanup
2013-07-19 15:37:56 -07:00
Andrej Mitrovic
443b54e30b Merge pull request #1362 from WebDrake/randomshuffle
Fix Issue 9607 - std.random.randomShuffle() and partialShuffle() don't work with Xorshift.
2013-07-15 15:16:04 -07:00
Hackerpilot
6f9c22bfa9 Merge remote-tracking branch 'upstream/master' 2013-07-13 19:37:11 +00:00
Hackerpilot
ae1dcaa3e1 Removed empty declarations. Converted more C-style array declarations to D-style. Removed trailing whitespace 2013-07-13 19:34:37 +00:00
Joseph Rushton Wakeling
f323100217 Make Xorshift bit-related error messages more informative. 2013-07-09 10:48:06 +02:00
Joseph Rushton Wakeling
b03552d9ac Double safety check for Xorshift bit values. 2013-07-09 09:51:41 +02:00
Joseph Rushton Wakeling
c29e261268 Correct typo in Xorshift160 which was leading to non-uniform behaviour.
The original typo derives directly from George Marsaglia's paper
introducing the Xorshift RNGs.  The original checking values, derived
from that code, thus also reflect the typo.

A corrected version of the reference code is available from
https://github.com/WebDrake/xorshift/ and has been used to
generate the updated checking values.
2013-07-08 22:45:31 +02:00
Joseph Rushton Wakeling
e1bbe0165d Correct typo in Xorshift32 which was leading to non-uniform behaviour.
The original typo derives directly from George Marsaglia's paper
introducing the Xorshift RNGs.  The original checking values, derived
from that code, thus also reflect the typo.

A corrected version of the reference code is available from
https://github.com/WebDrake/xorshift/ and has been used to
generate the updated checking values.
2013-07-08 22:02:34 +02:00
Joseph Rushton Wakeling
ec53fdd5fa Specifically check for 192-bit option in std.random.XorshiftEngine. 2013-07-08 21:55:23 +02:00
Andrej Mitrovic
257399827a Merge pull request #1202 from timotheecour/patch-1
Update random.d
2013-07-05 08:06:48 -07:00
Hackerpilot
13a6e6ac5c Converted C-style array declarations to D-style 2013-07-03 00:06:32 +00:00
Joseph Rushton Wakeling
32b11031a4 Restrict PseudoRngTypes access to package level. 2013-06-22 20:49:52 +01:00
Joseph Rushton Wakeling
e86bc65639 Fix Issue 9607 - std.random.randomShuffle() and partialShuffle()
don't work with Xorshift.

This is an instance of Issue 2803, a clash between a template
parameter and a default argument.  I've used the workaround
proposed in that issue thread:
http://d.puremagic.com/issues/show_bug.cgi?id=2803#c1

Tests have been included to ensure that these functions work
with all possible RNG types.
2013-06-22 09:43:56 +01:00
Joseph Rushton Wakeling
da1dfefba1 Many asserts in std.random can be made static. 2013-06-21 10:49:34 +01:00
Joseph Rushton Wakeling
66cc47b3c1 Remove superflous assert(false) and return statements. 2013-06-21 00:54:37 +01:00
Joseph Rushton Wakeling
0d5162b826 Unittest for MersenneTwisterEngine .save. 2013-06-20 20:34:09 +01:00
Joseph Rushton Wakeling
037ec6e3d1 Complete non-static code coverage for LinearCongruentialEngine unittests.
Unittests for LinearCongruentialEngine were previously missing the
constructor and the .save and .opEquals() methods.

Code coverage analysis still fails to pick up on the static methods
and the contents of a static if scope in lines 374-382 of .popFront().
2013-06-20 20:05:53 +01:00
Joseph Rushton Wakeling
fddc91d5c3 Complete code coverage for Xorshift unittests.
Unittests for Xorshift were previously failing to cover the
constructor, and the .seed(), .save and .opEquals() methods.
2013-06-20 20:02:55 +01:00
Joseph Rushton Wakeling
02fe8ad76a Ensure adequate code coverage from std.random.RandomSample unittests.
The old unittests were missing coverage of large sections of
RandomSample.skip() because the ratios of sample size to source size
were such that Algorithm A was always being chosen over Algorithm D.

The new unittests fix this and also extend coverage to a number of
other areas previously not addressed.  There are also currently-failing
tests commented out with version(none) that can be used to verify
future bugfixes and improvements.

A few lines in skip() remain uncovered simply because they depend on
runtime conditions that are extremely rare.
2013-06-20 19:39:02 +01:00
Joseph Rushton Wakeling
bc386eed72 Spread long statements across several lines. 2013-06-16 15:53:46 +01:00
Joseph Rushton Wakeling
643a2565a1 More formatting corrections. 2013-06-16 15:48:15 +01:00
Joseph Rushton Wakeling
22d26ef8c1 Simplify assert conditions. 2013-06-16 15:26:56 +01:00
Joseph Rushton Wakeling
91b2c664c7 Fix up spacing and brackets for if statements. 2013-06-16 15:21:04 +01:00
Joseph Rushton Wakeling
ca7abe9454 Indentation corrections. :-( 2013-06-09 16:34:05 +02:00
Joseph Rushton Wakeling
a998d02498 RandomSample assertions to ensure skip sizes respect number of items remaining. 2013-06-09 16:18:53 +02:00
Joseph Rushton Wakeling
8da0f13596 Issue 10269 - RandomSample should use popFrontExactly, not popFrontN, when skipping across input range
This small tweak has been accompanied by a couple of extra checks
to ensure that users do not request more sample points than are
available in the input, which could otherwise be the source of
exceptions.

There exists one remaining case where RandomSample may fail: if it
is given an InputRange without the .length property, and the user
indicates that the total number of items available is greater
than what the InputRange actually contains.  In this case an
exception is thrown from std.array.popFront() line 450,
"Attempting to popFront() past the end of an array", or from
std.array.front() line 624, "Attempting to fetch the front of an
empty array."
2013-06-09 15:23:30 +02:00
Joseph Rushton Wakeling
004ce96368 Unittests for randomSample being passed an InputRange.
The assignment of _input = input has been moved from
initialize() to the constructors so as to avoid
problems with nested structs.
2013-06-04 21:54:14 +02:00
Joseph Rushton Wakeling
cbdd14b57b Issue 10265 - RandomSample fails when passed an InputRange as input
* Issue fixed by making presence of save() property conditional
   on input being a ForwardRange.
2013-06-04 19:27:58 +02:00
Walter Bright
a2c9066282 immutable should be an enum 2013-05-25 13:32:53 -07:00
Nils Boßung
4238f5b3ce add an overload for uniform!enum that takes a generator 2013-04-06 23:01:37 +02:00
Timothee Cour
a983cd6d79 Update random.d
fixed spacing
2013-03-12 18:21:47 -07:00
Timothee Cour
e3221dd626 Update random.d
fix wrong usage in doc example (Random gen(unpredictableSeed)).
2013-03-12 16:44:55 -07:00
Andrej Mitrovic
c95100ba78 Fixes Issue 9339 - Uniform for enums. 2013-01-22 02:20:43 +01:00
k-hara
01df2f60be Remove redundant parenthesis for getters, and use assignment syntax for setters 2012-11-23 15:07:17 +09:00
dsimcha
f2c17d9b0d Add std.random.partialShuffle. 2012-07-25 21:37:41 -04:00
Andrei Alexandrescu
92335506d3 Merge pull request #654 from dawgfoto/fix8314
fix issue 8314
2012-07-22 19:50:22 -07:00
jmdavis
735c2adbda Changes required for issue# 6277. 2012-07-21 01:57:28 -07:00
Martin Nowak
aa896e08cc set random generator in constructor
- Bug 8314 was already fixed by adding a _first flag
2012-07-20 16:34:49 +02:00
jmdavis
28781bfb9f Old deprecations which were not properly taken care of previously. 2012-07-07 02:03:49 -07:00
Andrei Alexandrescu
ae15e0ec14 Merge pull request #553 from WebDrake/master
Rewrite of RandomSample to use Jeffrey Scott Vitter's Algorithm D.
2012-07-01 19:14:52 -07:00
Johannes Pfau
589218003d Fix isSeedable documentation 2012-06-18 14:52:44 +02:00
Johannes Pfau
c0be641cd5 Add seed(InputRange) overload to MersenneTwisterEngine 2012-06-17 13:26:49 +02:00
Joseph Rushton Wakeling
205c3bf4cb Fix problem of first sample point always being identical. 2012-05-09 20:57:52 +02:00
Joseph Rushton Wakeling
5f539a1622 Fix link errors in Ddoc comments. 2012-05-04 20:19:44 +02:00
Joseph Rushton Wakeling
d7f5bb0aa5 Small typo correction in comment/doc. 2012-05-04 20:07:10 +02:00
Joseph Rushton Wakeling
40a79b32e2 RandomSample should check if input is InputRange. 2012-05-04 19:04:52 +02:00
Joseph Rushton Wakeling
56ef13997e Bring code in line with D style. 2012-05-04 14:22:34 +02:00
Joseph Rushton Wakeling
39bc5ae412 skip() and skipA() should not be called as properties.
Ensures code builds with -property and -unittest flags
both enabled.
2012-05-04 12:56:59 +02:00
jmdavis
76def7af85 Fix Issue# 8026.
I added template constraints to all of the templates missing template
constraints in std.random - including randomShuffle, per the bug.
2012-05-03 19:47:15 -07:00
jmdavis
088a228b34 Fixed incorrectly named enum. 2012-05-03 19:40:40 -07:00