Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions std/algorithm/internal.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ version(unittest)

package string[] rndstuff(T : string)()
{
import std.random : Random, unpredictableSeed, uniform;
import std.random : Random = Xorshift, uniform;

static Random rnd;
static bool first = true;
if (first)
{
rnd = Random(unpredictableSeed);
rnd.seed(234_567_891);
first = false;
}
string[] result =
Expand All @@ -46,13 +46,13 @@ version(unittest)

package int[] rndstuff(T : int)()
{
import std.random : Random, unpredictableSeed, uniform;
import std.random : Random = Xorshift, uniform;

static Random rnd;
static bool first = true;
if (first)
{
rnd = Random(unpredictableSeed);
rnd = Random(345_678_912);
first = false;
}
int[] result = new int[uniform(minArraySize, maxArraySize, rnd)];
Expand Down
4 changes: 2 additions & 2 deletions std/algorithm/iteration.d
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ private struct MapResult(alias fun, Range)
import std.internal.test.dummyrange;
import std.range;
import std.typecons : tuple;
import std.random : unpredictableSeed, uniform, Random;
import std.random : uniform, Random = Xorshift;

int[] arr1 = [ 1, 2, 3, 4 ];
const int[] arr1Const = arr1;
Expand Down Expand Up @@ -749,7 +749,7 @@ private struct MapResult(alias fun, Range)
assert(fibsSquares.front == 9);

auto repeatMap = map!"a"(repeat(1));
auto gen = Random(unpredictableSeed);
auto gen = Random(123_456_789);
auto index = uniform(0, 1024, gen);
static assert(isInfinite!(typeof(repeatMap)));
assert(repeatMap[index] == 1);
Expand Down
4 changes: 2 additions & 2 deletions std/algorithm/mutation.d
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ if (isInputRange!InputRange && isForwardRange!ForwardRange)
{
import std.algorithm.comparison : equal;
import std.conv : text;
import std.random : Random, unpredictableSeed, uniform;
import std.random : Random = Xorshift, uniform;

// a more elaborate test
{
auto rnd = Random(unpredictableSeed);
auto rnd = Random(123_456_789);
int[] a = new int[uniform(100, 200, rnd)];
int[] b = new int[uniform(100, 200, rnd)];
foreach (ref e; a) e = uniform(-100, 100, rnd);
Expand Down
24 changes: 12 additions & 12 deletions std/algorithm/sorting.d
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ if (isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && hasAssig
import std.algorithm.iteration : map;
import std.random;
import std.stdio;
auto s = unpredictableSeed;
auto g = Random(s);
auto s = 123_456_789;
auto g = Xorshift(s);
a = iota(0, uniform(1, 1000, g))
.map!(_ => uniform(-1000, 1000, g))
.array;
Expand Down Expand Up @@ -883,9 +883,9 @@ if (ss == SwapStrategy.unstable && isRandomAccessRange!Range

@safe unittest
{
import std.random : Random, uniform, unpredictableSeed;
import std.random : Random = Xorshift, uniform;

immutable uint[] seeds = [3923355730, 1927035882, unpredictableSeed];
immutable uint[] seeds = [3923355730, 1927035882];
foreach (s; seeds)
{
auto r = Random(s);
Expand Down Expand Up @@ -1710,7 +1710,7 @@ private void shortSort(alias less, Range)(Range r)

@safe unittest
{
import std.random : Random, uniform;
import std.random : Random = Xorshift, uniform;

auto rnd = Random(1);
auto a = new int[uniform(100, 200, rnd)];
Expand Down Expand Up @@ -1949,12 +1949,12 @@ if (((ss == SwapStrategy.unstable && (hasSwappableElements!Range ||
{
import std.algorithm.internal : rndstuff;
import std.algorithm.mutation : swapRanges;
import std.random : Random, unpredictableSeed, uniform;
import std.random : Random = Xorshift, uniform;
import std.uni : toUpper;

// sort using delegate
auto a = new int[100];
auto rnd = Random(unpredictableSeed);
auto rnd = Random(123_456_789);
foreach (ref e; a)
{
e = uniform(-100, 100, rnd);
Expand Down Expand Up @@ -3457,7 +3457,7 @@ private T[] randomArray(Flag!"exactSize" flag = No.exactSize, T = int)(
T minValue = 0, T maxValue = 255)
{
import std.algorithm.iteration : map;
import std.random : unpredictableSeed, Random, uniform;
import std.random : uniform;
auto size = flag == Yes.exactSize ? maxSize : uniform(1, maxSize);
return iota(0, size).map!(_ => uniform(minValue, maxValue)).array;
}
Expand Down Expand Up @@ -3513,9 +3513,9 @@ private T[] randomArray(Flag!"exactSize" flag = No.exactSize, T = int)(
{
import std.algorithm.comparison : max, min;
import std.algorithm.iteration : reduce;
import std.random : Random, uniform, unpredictableSeed;
import std.random : Random = Xorshift, uniform;

immutable uint[] seeds = [90027751, 2709791795, 1374631933, 995751648, 3541495258, 984840953, unpredictableSeed];
immutable uint[] seeds = [90027751, 2709791795, 1374631933, 995751648, 3541495258, 984840953];
foreach (s; seeds)
{
auto r = Random(s);
Expand Down Expand Up @@ -3718,10 +3718,10 @@ if (isInputRange!(SRange) && isRandomAccessRange!(TRange)

@system unittest
{
import std.random : Random, unpredictableSeed, uniform, randomShuffle;
import std.random : Random = Xorshift, uniform, randomShuffle;
import std.typecons : Yes;

auto r = Random(unpredictableSeed);
auto r = Random(123_456_789);
ptrdiff_t[] a = new ptrdiff_t[uniform(1, 1000, r)];
foreach (i, ref e; a) e = i;
randomShuffle(a, r);
Expand Down
37 changes: 20 additions & 17 deletions std/random.d
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ alias MinstdRand = LinearCongruentialEngine!(uint, 48_271, 0, 2_147_483_647);
// Check .save works
static foreach (Type; std.meta.AliasSeq!(MinstdRand0, MinstdRand))
{{
auto rnd1 = Type(unpredictableSeed);
auto rnd1 = Type(123_456_789);
rnd1.popFront();
auto rnd2 = rnd1.save;
assert(rnd1 == rnd2);
// Enable next test when RNGs are reference types
Expand Down Expand Up @@ -991,11 +992,11 @@ alias Mt19937_64 = MersenneTwisterEngine!(ulong, 64, 312, 156, 31,

Mt19937 gen;

assertThrown(gen.seed(map!((a) => unpredictableSeed)(repeat(0, 623))));
assertThrown(gen.seed(map!((a) => 123_456_789U)(repeat(0, 623))));

gen.seed(map!((a) => unpredictableSeed)(repeat(0, 624)));
gen.seed(123_456_789U.repeat(624));
//infinite Range
gen.seed(map!((a) => unpredictableSeed)(repeat(0)));
gen.seed(123_456_789U.repeat);
}

@safe pure nothrow unittest
Expand All @@ -1020,7 +1021,8 @@ alias Mt19937_64 = MersenneTwisterEngine!(ulong, 64, 312, 156, 31,
// Check .save works
static foreach (Type; std.meta.AliasSeq!(Mt19937, Mt19937_64))
{{
auto gen1 = Type(unpredictableSeed);
auto gen1 = Type(123_456_789);
gen1.popFront();
auto gen2 = gen1.save;
assert(gen1 == gen2); // Danger, Will Robinson -- no opEquals for MT
// Enable next test when RNGs are reference types
Expand Down Expand Up @@ -1323,7 +1325,8 @@ alias Xorshift = Xorshift128; /// ditto
// Check .save works
foreach (Type; XorshiftTypes)
{
auto rnd1 = Type(unpredictableSeed);
auto rnd1 = Type(123_456_789);
rnd1.popFront();
auto rnd2 = rnd1.save;
assert(rnd1 == rnd2);
// Enable next test when RNGs are reference types
Expand All @@ -1343,7 +1346,7 @@ alias Xorshift = Xorshift128; /// ditto
foreach (Rng; PseudoRngTypes)
{
static assert(isUniformRNG!Rng);
auto rng = Rng(unpredictableSeed);
auto rng = Rng(123_456_789);
}
}

Expand Down Expand Up @@ -1720,7 +1723,7 @@ if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) &&
@safe unittest
{
import std.conv : to;
auto gen = Mt19937(unpredictableSeed);
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));

auto a = uniform(0, 1024, gen);
Expand Down Expand Up @@ -2056,7 +2059,7 @@ do

static foreach (T; std.meta.AliasSeq!(float, double, real))
{{
UniformRNG rng = UniformRNG(unpredictableSeed);
UniformRNG rng = UniformRNG(123_456_789);

auto a = uniform01();
assert(is(typeof(a) == double));
Expand Down Expand Up @@ -2240,7 +2243,7 @@ if (isRandomAccessRange!Range)
// Also tests partialShuffle indirectly.
auto a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
auto b = a.dup;
auto gen = RandomGen(unpredictableSeed);
auto gen = RandomGen(123_456_789);
randomShuffle(a, gen);
sort(a);
assert(a == b);
Expand Down Expand Up @@ -2421,7 +2424,7 @@ do

@safe unittest
{
auto rnd = Random(unpredictableSeed);
auto rnd = Xorshift(123_456_789);
auto i = dice(rnd, 0.0, 100.0);
assert(i == 1);
i = dice(rnd, 100.0, 0.0);
Expand Down Expand Up @@ -2628,11 +2631,11 @@ if (isRandomAccessRange!Range)
}
else
{
auto rng = UniformRNG(unpredictableSeed);
auto rng = UniformRNG(123_456_789);
auto rc = randomCover(a, rng);
static assert(isForwardRange!(typeof(rc)));
// check for constructor passed a value-type RNG
auto rc2 = RandomCover!(int[], UniformRNG)(a, UniformRNG(unpredictableSeed));
auto rc2 = RandomCover!(int[], UniformRNG)(a, UniformRNG(987_654_321));
static assert(isForwardRange!(typeof(rc2)));
auto rcEmpty = randomCover(c, rng);
assert(rcEmpty.length == 0);
Expand Down Expand Up @@ -3199,7 +3202,7 @@ if (isInputRange!Range && hasLength!Range && isUniformRNG!UniformRNG)
{
auto sample =
RandomSample!(TestInputRange, UniformRNG)
(TestInputRange(), 5, 10, UniformRNG(unpredictableSeed));
(TestInputRange(), 5, 10, UniformRNG(987_654_321));
static assert(isInputRange!(typeof(sample)));
static assert(!isForwardRange!(typeof(sample)));
}
Expand All @@ -3215,7 +3218,7 @@ if (isInputRange!Range && hasLength!Range && isUniformRNG!UniformRNG)
{
auto sample =
RandomSample!(typeof(TestInputRange().takeExactly(10)), UniformRNG)
(TestInputRange().takeExactly(10), 5, 10, UniformRNG(unpredictableSeed));
(TestInputRange().takeExactly(10), 5, 10, UniformRNG(654_321_987));
static assert(isInputRange!(typeof(sample)));
static assert(!isForwardRange!(typeof(sample)));
}
Expand All @@ -3229,7 +3232,7 @@ if (isInputRange!Range && hasLength!Range && isUniformRNG!UniformRNG)
{
auto sample =
RandomSample!(int[], UniformRNG)
(a, 5, UniformRNG(unpredictableSeed));
(a, 5, UniformRNG(321_987_654));
static assert(isForwardRange!(typeof(sample)));
}
}
Expand All @@ -3241,7 +3244,7 @@ if (isInputRange!Range && hasLength!Range && isUniformRNG!UniformRNG)
{
auto sample =
RandomSample!(int[], UniformRNG)
(a, 5, UniformRNG(unpredictableSeed));
(a, 5, UniformRNG(789_123_456));
static assert(isInputRange!(typeof(sample)));
static assert(!isForwardRange!(typeof(sample)));
}
Expand Down