Use std::shuffle instead of std::random_shuffle

mcgrathr points out in https://chromium-review.googlesource.com/1172090
that std::random_shuffle is deprecated in C++14 and removed in C++17.
Rather than having mini_chromium mimic Chromium’s base by providing
RandomShuffle (Chromium 5de2157f1e7f), just use the standard library’s
std::shuffle with mt19937(random_generator).

Change-Id: I8c2b3101bf324350351dba9edda1ba230b1c6710
Reviewed-on: https://chromium-review.googlesource.com/1176122
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Mark Mentovai 2018-08-15 13:27:22 -04:00 committed by Commit Bot
parent 3ab5d5eff2
commit 5c6e19f000

View File

@ -18,11 +18,11 @@
#include <stdlib.h>
#include <algorithm>
#include <random>
#include <string>
#include <vector>
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "test/scoped_temp_dir.h"
@ -218,11 +218,8 @@ TEST(PruneCrashReports, PruneOrder) {
temp.creation_time = NDaysAgo(i * 10);
reports.push_back(temp);
}
// The randomness from std::rand() is not, so use a better rand() instead.
const auto random_generator = [](ptrdiff_t rand_max) {
return base::RandInt(0, base::checked_cast<int>(rand_max) - 1);
};
std::random_shuffle(reports.begin(), reports.end(), random_generator);
std::mt19937 urng(std::random_device{}());
std::shuffle(reports.begin(), reports.end(), urng);
std::vector<CrashReportDatabase::Report> pending_reports(
reports.begin(), reports.begin() + 5);
std::vector<CrashReportDatabase::Report> completed_reports(