Commit 1fcbca3e authored by Haocheng LIU's avatar Haocheng LIU

Replace std::random_shuffle with std::shuffle

std::random_shuffle is deprecated in C++14 because it's using std::rand
which uses a non uniform distribution and the underlying algorithm is
unspecified. Using std::shuffle can provide a reliable result in a 64
bit version.
parent 0a3e5371
Replace std::random_shuffle with std::shuffle
std::random_shuffle is deprecated in C++14 because it's using std::rand
which uses a non uniform distribution and the underlying algorithm is
unspecified. Using std::shuffle can provide a reliable result in a 64 bit version.
......@@ -31,6 +31,7 @@
#include <algorithm>
#include <iostream>
#include <random>
namespace vtkm
{
......@@ -59,7 +60,9 @@ private:
{
const vtkm::Id nvals = 11;
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
std::random_shuffle(data, data + nvals);
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(data, data + nvals, urng);
auto field =
vtkm::cont::make_Field("TestField", vtkm::cont::Field::Association::POINTS, data, nvals);
......@@ -77,9 +80,11 @@ private:
const vtkm::Id nvals = 11;
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
vtkm::Vec<T, NumberOfComponents> fieldData[nvals];
std::random_device rng;
std::mt19937 urng(rng());
for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i)
{
std::random_shuffle(data, data + nvals);
std::shuffle(data, data + nvals, urng);
for (vtkm::Id j = 0; j < nvals; ++j)
{
fieldData[j][i] = data[j];
......
......@@ -32,6 +32,7 @@
#include <algorithm>
#include <iterator>
#include <random>
#include <vector>
namespace vtkm
......@@ -63,7 +64,9 @@ private:
*i = TestValue(pos, T());
}
std::random_shuffle(data.begin(), data.end());
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(data.begin(), data.end(), urng);
return vtkm::cont::make_ArrayHandle(data);
}
......
Markdown is supported
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