mCRL2
Loading...
Searching...
No Matches
shuffle.h
Go to the documentation of this file.
1// Copyright (c) 2009-2013 University of Twente
2// Copyright (c) 2009-2013 Michael Weber <michaelw@cs.utwente.nl>
3// Copyright (c) 2009-2013 Maks Verver <maksverver@geocities.com>
4// Copyright (c) 2009-2013 Eindhoven University of Technology
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10#ifndef MCRL2_PG_SHUFFLE_H
11#define MCRL2_PG_SHUFFLE_H
12
13#include <algorithm>
14#include <vector>
15#include <cstdlib>
16
17/* Randomly shuffle the given vector. This is similar to std::random_shuffle
18 on a vector, except that this uses rand() while the random source for
19 std::random_shuffle is unspecified. */
20template<class T>
21static void shuffle_vector(std::vector<T> &v)
22{
23 std::size_t n = v.size();
24 for (std::size_t i = 0; i < n; ++i)
25 {
26 std::swap(v[i], v[i + rand()%(n - i)]);
27 }
28}
29
30#endif /* ndef MCRL2_PG_SHUFFLE_H */
void swap(atermpp::unprotected_aterm_core &t1, atermpp::unprotected_aterm_core &t2) noexcept
Swaps two aterms.
Definition aterm.h:462
static void shuffle_vector(std::vector< T > &v)
Definition shuffle.h:21