scc 2025.09
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
29namespace scc {
38class MT19937 {
39public:
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 }
64
69 template <typename T> static T uniform() {
70 std::uniform_int_distribution<T> u;
71 return u(inst());
72 }
73
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 }
85
90 static double normal() {
91 std::normal_distribution<> u;
92 return u(inst());
93 }
94
99 static double lognormal() {
100 std::lognormal_distribution<> u;
101 return u(inst());
102 }
103
104private:
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)
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)
SCC TLM utilities.