scc  2022.4.0
SystemC components library
mt19937_rng.h
1 /*******************************************************************************
2  * Copyright 2020-2022 MINRES Technologies GmbH
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 #ifndef _SCC_MT19937_RNG_H_
18 #define _SCC_MT19937_RNG_H_
19 
20 #include <assert.h>
21 #include <iostream>
22 #include <random>
23 
29 namespace scc {
38 class MT19937 {
39 public:
45  static void seed(uint64_t new_seed = std::mt19937_64::default_seed);
53  static void enable_global_seed(bool enable);
54 
60  static uint64_t uniform() {
61  std::uniform_int_distribution<uint64_t> u;
62  return u(inst());
63  }
69  template <typename T> static T uniform() {
70  std::uniform_int_distribution<T> u;
71  return u(inst());
72  }
80  static uint64_t uniform(uint64_t min, uint64_t max) {
81  assert(min < max);
82  std::uniform_int_distribution<uint64_t> u(min, max);
83  return u(inst());
84  }
90  static double normal() {
91  std::normal_distribution<> u;
92  return u(inst());
93  }
99  static double lognormal() {
100  std::lognormal_distribution<> u;
101  return u(inst());
102  }
103 
104 private:
105  static std::mt19937_64& inst();
106 };
107 
108 } // namespace scc // end of scc-sysc
110 #endif /* _SCC_MT19937_RNG_H_ */
a mersenne-twister based random number generator
Definition: mt19937_rng.h:38
static double normal()
Definition: mt19937_rng.h:90
static double lognormal()
Definition: mt19937_rng.h:99
static void enable_global_seed(bool enable)
Definition: mt19937_rng.cpp:69
static uint64_t uniform(uint64_t min, uint64_t max)
Definition: mt19937_rng.h:80
static uint64_t uniform()
Definition: mt19937_rng.h:60
static T uniform()
Definition: mt19937_rng.h:69
static void seed(uint64_t new_seed=std::mt19937_64::default_seed)
Definition: mt19937_rng.cpp:62
SCC SystemC utilities.