NuriKit
v0.1.0b2
Toggle main menu visibility
Loading...
Searching...
No Matches
include
nuri
random.h
Go to the documentation of this file.
1
//
2
// Project NuriKit - Copyright 2025 SNU Compbio Lab.
3
// SPDX-License-Identifier: Apache-2.0
4
//
5
6
#ifndef NURI_RANDOM_H_
7
#define NURI_RANDOM_H_
8
9
#include <algorithm>
10
#include <iterator>
11
#include <random>
12
13
#include <Eigen/Dense>
14
15
#include "
nuri/eigen_config.h
"
16
17
namespace
nuri
{
18
namespace
internal {
19
// NOLINTNEXTLINE(*-global-variables)
20
extern
thread_local
std::mt19937 rng;
21
22
template
<
typename
NT>
23
NT draw_uid(NT
min
, NT
max
) {
24
return
std::uniform_int_distribution<NT>(
min
,
max
- 1)(rng);
25
}
26
27
template
<
typename
NT>
28
NT draw_uid(NT
max
) {
29
return
draw_uid(
static_cast<
NT
>
(0),
max
);
30
}
31
32
template
<
typename
RT>
33
RT draw_urd(RT
min
, RT
max
) {
34
return
std::uniform_real_distribution<RT>(
min
,
max
)(rng);
35
}
36
37
template
<
typename
RT>
38
RT draw_urd(RT
max
) {
39
return
draw_urd(
static_cast<
RT
>
(0),
max
);
40
}
41
42
template
<
typename
CT,
typename
RT =
typename
CT::value_type>
43
auto
weighted_select(
const
CT &cutoffs,
const
RT base = 0) {
44
RT
max
= cutoffs[cutoffs.size() - 1];
45
RT p = draw_urd<RT>(base,
max
);
46
47
auto
it = std::lower_bound(std::begin(cutoffs), std::end(cutoffs) - 1, p);
48
return
it - std::begin(cutoffs);
49
}
50
51
extern
Vector3d random_unit();
52
53
extern
AngleAxisd random_rotation(
double
max_angle);
54
55
extern
void
seed_thread(
int
seed);
56
}
// namespace internal
57
}
// namespace nuri
58
59
#endif
/* NURI_RANDOM_H_ */
eigen_config.h
nuri
Definition
crdgen.h:16
nuri::min
constexpr T min(T a, T b)
Definition
utils.h:35
nuri::max
constexpr T max(T a, T b)
Definition
utils.h:51
Generated by
1.17.0