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

 Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ce1a28c9f Fri Aug 23 08:02:09 2019 +0200 at vie ago 23 08:10:11 CEST 2019