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 |
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 }
void shuffle(RandomIt first, RandomIt last, URBG &&g)
Uniform shuffle a sequence.
GLint * first
Definition: glext.h:3827
GLenum GLsizei n
Definition: glext.h:5074
GLubyte g
Definition: glext.h:6279
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020