votca 2024.2-dev
Loading...
Searching...
No Matches
random.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#ifndef VOTCA_TOOLS_RANDOM_H
19#define VOTCA_TOOLS_RANDOM_H
20
21// Standard includes
22#include <random>
23
24// Local VOTCA includes
25#include "types.h"
26
27namespace votca {
28namespace tools {
29
30class Random {
31 public:
32 void init(Index seed) {
33 if (seed < 0) {
34 throw std::runtime_error("seed integer must be positive.");
35 }
36 mt_ = std::mt19937(unsigned(seed));
37 }
38 // draws a random double from [0,1)
39 double rand_uniform() { return distribution_(mt_); }
40 // sets maxint for a uniform integer distribution [0,maxint]
41 void setMaxInt(Index maxint) {
42 int_distribution_ = std::uniform_int_distribution<Index>{0, maxint};
43 }
44 // draws from a uniform integer distribution [0,maxint]
46
47 private:
48 std::mt19937 mt_;
49 std::uniform_real_distribution<double> distribution_{0.0, 1.0};
50 std::uniform_int_distribution<Index> int_distribution_;
51};
52
53} // namespace tools
54} // namespace votca
55
56#endif // VOTCA_TOOLS_RANDOM_H
void setMaxInt(Index maxint)
Definition random.h:41
std::uniform_real_distribution< double > distribution_
Definition random.h:49
double rand_uniform()
Definition random.h:39
std::mt19937 mt_
Definition random.h:48
Index rand_uniform_int()
Definition random.h:45
void init(Index seed)
Definition random.h:32
std::uniform_int_distribution< Index > int_distribution_
Definition random.h:50
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26