Commit 6dea0727 authored by Volker Krause's avatar Volker Krause
Browse files

Port away from std::random_shuffle, that's gone in C++17

parent cac0b617
......@@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// STL
#include <algorithm>
#include <ctime>
#include <random>
// Qt
#include <QAction>
......@@ -52,27 +53,6 @@ enum State {
WaitForEndOfUrl,
};
/**
* This class generate random numbers which are not the same between two runs
* of Gwenview. See bug #132334
*/
class RandomNumberGenerator
{
public:
RandomNumberGenerator()
: mSeed(time(nullptr))
{
}
int operator()(int n)
{
return rand_r(&mSeed) % n;
}
private:
unsigned int mSeed;
};
struct SlideShowPrivate {
QTimer *mTimer = nullptr;
State mState;
......@@ -123,8 +103,9 @@ struct SlideShowPrivate {
void initShuffledUrls()
{
mShuffledUrls = mUrls;
RandomNumberGenerator generator;
std::random_shuffle(mShuffledUrls.begin(), mShuffledUrls.end(), generator);
std::random_device rd;
std::mt19937 generator(rd());
std::shuffle(mShuffledUrls.begin(), mShuffledUrls.end(), generator);
// Ensure the first url is different from the previous last one, so that
// last url does not stay visible twice longer than usual
if (mLastShuffledUrl == mShuffledUrls.first() && mShuffledUrls.count() > 1) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment