Skip to content

Commit 8163917

Browse files
Merge pull request #3069 from SunBlack/modernize-replace-random-shuffle
Replace random_shuffle by shuffle
2 parents 9c88a62 + 27a5379 commit 8163917

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

outofcore/include/pcl/outofcore/impl/octree_base_node.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
// C++
4545
#include <iostream>
4646
#include <fstream>
47+
#include <random>
4748
#include <sstream>
4849
#include <string>
4950
#include <exception>
@@ -1682,7 +1683,7 @@ namespace pcl
16821683
}//force the payload cache to deconstruct here
16831684

16841685
//use STL random_shuffle and push back a random selection of the points onto our list
1685-
std::random_shuffle (payload_cache_within_region.begin (), payload_cache_within_region.end ());
1686+
std::shuffle (payload_cache_within_region.begin (), payload_cache_within_region.end (), std::mt19937(std::random_device()()));
16861687
size_t numpick = static_cast<size_t> (percent * static_cast<double> (payload_cache_within_region.size ()));;
16871688

16881689
for (size_t i = 0; i < numpick; i++)

recognition/include/pcl/recognition/hv/hv_go.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include <random>
11+
1012
#include <boost/graph/graph_traits.hpp>
1113
#include <boost/graph/adjacency_list.hpp>
1214

@@ -178,7 +180,7 @@ namespace pcl
178180

179181
void refresh(mets::feasible_solution& /*s*/)
180182
{
181-
std::random_shuffle (moves_m.begin (), moves_m.end ());
183+
std::shuffle (moves_m.begin (), moves_m.end (), std::mt19937(std::random_device()()));
182184
}
183185

184186
};

recognition/src/face_detection/face_detector_data_provider.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <pcl/features/integral_image_normal.h>
55
#include <pcl/io/pcd_io.h>
66

7+
#include <random>
8+
79
//Uncomment the following lines and set PCL_FACE_DETECTION_VIS_TRAINING_FDDP to 1
810
//to visualize the training process and change the CMakeLists.txt accordingly.
911
//#include <pcl/visualization/pcl_visualizer.h>
@@ -136,13 +138,14 @@ void pcl::face_detection::FaceDetectorDataProvider<FeatureType, DataSet, LabelTy
136138
if (min_images_per_bin_ != -1)
137139
{
138140
std::cout << "Reducing unbalance of the dataset." << std::endl;
141+
std::mt19937 rng((std::random_device()()));
139142
for (int i = 0; i < num_yaw; i++)
140143
{
141144
for (int j = 0; j < num_pitch; j++)
142145
{
143146
if (yaw_pitch_bins[i][j] >= min_images_per_bin_)
144147
{
145-
std::random_shuffle (image_files_per_bin[i][j].begin (), image_files_per_bin[i][j].end ());
148+
std::shuffle (image_files_per_bin[i][j].begin (), image_files_per_bin[i][j].end (), rng);
146149
image_files_per_bin[i][j].resize (min_images_per_bin_);
147150
yaw_pitch_bins[i][j] = min_images_per_bin_;
148151
}
@@ -167,8 +170,8 @@ template<class FeatureType, class DataSet, class LabelType, class ExampleIndex,
167170
void pcl::face_detection::FaceDetectorDataProvider<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>::getDatasetAndLabels(DataSet & data_set,
168171
std::vector<LabelType> & label_data, std::vector<ExampleIndex> & examples)
169172
{
170-
srand (static_cast<unsigned int>(time (nullptr)));
171-
std::random_shuffle (image_files_.begin (), image_files_.end ());
173+
std::mt19937 rng((std::random_device()()));
174+
std::shuffle (image_files_.begin (), image_files_.end (), rng);
172175
std::vector < std::string > files;
173176
files = image_files_;
174177
files.resize (std::min (num_images_, static_cast<int> (files.size ())));
@@ -393,8 +396,8 @@ void pcl::face_detection::FaceDetectorDataProvider<FeatureType, DataSet, LabelTy
393396
}
394397

395398
//shuffle and resize
396-
std::random_shuffle (positive_p.begin (), positive_p.end ());
397-
std::random_shuffle (negative_p.begin (), negative_p.end ());
399+
std::shuffle (positive_p.begin (), positive_p.end (), rng);
400+
std::shuffle (negative_p.begin (), negative_p.end (), rng);
398401
positive_p.resize (N_patches);
399402
negative_p.resize (N_patches);
400403

0 commit comments

Comments
 (0)