aboutsummaryrefslogtreecommitdiffstats
path: root/src/Queue.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-07 21:07:30 +0100
committerMax Kellermann <max@duempel.org>2013-01-07 22:00:57 +0100
commitc6281b2680ec10d31d00869091a0f918041a0554 (patch)
treef6d7bcb97c393aacd1ff287160ecda3d43aa5e21 /src/Queue.cxx
parent5b8b7d14127a5ea9ce8f0301c92267f86eeab85a (diff)
downloadmpd-c6281b2680ec10d31d00869091a0f918041a0554.tar.gz
mpd-c6281b2680ec10d31d00869091a0f918041a0554.tar.xz
mpd-c6281b2680ec10d31d00869091a0f918041a0554.zip
Queue: use C++ random instead of GLib's GRand
Diffstat (limited to '')
-rw-r--r--src/Queue.cxx25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/Queue.cxx b/src/Queue.cxx
index 5b3e00d90..8dcb96aa0 100644
--- a/src/Queue.cxx
+++ b/src/Queue.cxx
@@ -33,8 +33,7 @@ queue::queue(unsigned _max_length)
repeat(false),
single(false),
consume(false),
- random(false),
- rand(g_rand_new())
+ random(false)
{
for (unsigned i = 0; i < max_length * QUEUE_HASH_MULT; ++i)
id_to_position[i] = -1;
@@ -47,8 +46,6 @@ queue::~queue()
g_free(items);
g_free(order);
g_free(id_to_position);
-
- g_rand_free(rand);
}
/**
@@ -375,8 +372,8 @@ queue::ShuffleOrderRange(unsigned start, unsigned end)
assert(start <= end);
assert(end <= length);
- for (unsigned i = start; i < end; ++i)
- SwapOrders(i, g_rand_int_range(rand, i, end));
+ rand.AutoCreate();
+ std::shuffle(order + start, order + end, rand);
}
/**
@@ -426,13 +423,19 @@ queue::ShuffleOrder()
void
queue::ShuffleOrderFirst(unsigned start, unsigned end)
{
- SwapOrders(start, g_rand_int_range(rand, start, end));
+ rand.AutoCreate();
+
+ std::uniform_int_distribution<unsigned> distribution(start, end - 1);
+ SwapOrders(start, distribution(rand));
}
void
queue::ShuffleOrderLast(unsigned start, unsigned end)
{
- SwapOrders(end - 1, g_rand_int_range(rand, start, end));
+ rand.AutoCreate();
+
+ std::uniform_int_distribution<unsigned> distribution(start, end - 1);
+ SwapOrders(end - 1, distribution(rand));
}
void
@@ -441,8 +444,12 @@ queue::ShuffleRange(unsigned start, unsigned end)
assert(start <= end);
assert(end <= length);
+ rand.AutoCreate();
+
for (unsigned i = start; i < end; i++) {
- unsigned ri = g_rand_int_range(rand, i, end);
+ std::uniform_int_distribution<unsigned> distribution(start,
+ end - 1);
+ unsigned ri = distribution(rand);
SwapPositions(i, ri);
}
}