• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2016 Edward Diener
2 *
3 * Use, modification and distribution is subject to the
4 * Boost Software License, Version 1.0. (See accompanying
5 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6 */
7 
8 #ifndef BOOST_POOL_TEST_RANDOM_SHUFFLE_HPP
9 #define BOOST_POOL_TEST_RANDOM_SHUFFLE_HPP
10 
11 #include <cstdlib>
12 #include <iterator>
13 #include <algorithm>
14 
15 template< class RandomIt >
pool_test_random_shuffle(RandomIt first,RandomIt last)16 void pool_test_random_shuffle( RandomIt first, RandomIt last )
17 {
18     typename std::iterator_traits<RandomIt>::difference_type i, n;
19     n = last - first;
20     for (i = n-1; i > 0; --i) {
21         using std::swap;
22         swap(first[i], first[std::rand() % (i+1)]);
23     }
24 }
25 
26 #endif // BOOST_POOL_TEST_RANDOM_SHUFFLE_HPP
27