VPTissue Reference Manual
DurstenfeldShuffle.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "DurstenfeldShuffle.h"
21 
22 #include "RandomEngine.h"
23 
24 #include <trng/uniform_int_dist.hpp>
25 #include <vector>
26 
27 using namespace std;
28 
29 namespace SimPT_Sim {
30 
31 void DurstenfeldShuffle::Fill(vector<unsigned int>& v, RandomEngine& r)
32 {
33  v[0] = 0U;
34  for (unsigned int i = 1; i < v.size(); i++) {
35  const auto j = r.GetGenerator(trng::uniform_int_dist(0U, i))();
36  v[i] = v[j];
37  v[j] = i;
38  }
39 
40 }
41 
42 } // namespace
STL namespace.
Interface of RandomEngine.
Interface for DurstenfeldShuffle.
Namespace for the core simulator.