Main MRPT website > C++ reference for MRPT 1.9.9
random_shuffle.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <utility> // std::swap
13 #include <iterator> // iterator_traits
14 #include <random> // uniform_int_distribution
15 
16 namespace mrpt {
17 namespace random
18 {
19 /** Uniform shuffle a sequence.
20  *\ingroup mrpt_random_grp
21  */
22 template<class RandomIt, class URBG>
23 void shuffle(RandomIt first, RandomIt last, URBG&& g)
24 {
25  typedef typename std::iterator_traits<RandomIt>::difference_type diff_t;
26  typedef std::uniform_int_distribution<diff_t> distr_t;
27  typedef typename distr_t::param_type param_t;
28  distr_t D;
29  diff_t n = last - first;
30  for (diff_t i = n - 1; i > 0; --i)
31  std::swap(first[i], first[D(g, param_t(0, i))]);
32 }
33 
34 /** Uniform shuffle a sequence.
35  *\ingroup mrpt_random_grp
36  */
37 template <class RandomIt>
38 void shuffle(RandomIt first, RandomIt last)
39 {
40  std::random_device rd; // used for random seed
41  std::mt19937 g(rd());
43 }
44 
45 }
46 }
n
GLenum GLsizei n
Definition: glext.h:5074
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
g
GLubyte g
Definition: glext.h:6279
mrpt::random::shuffle
void shuffle(RandomIt first, RandomIt last, URBG &&g)
Uniform shuffle a sequence.
Definition: random_shuffle.h:23
first
GLint * first
Definition: glext.h:3827



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST