Skip to content

Commit f9f6444

Browse files
authored
RandomDistributions: explicit parameters for of::random::uniform (#7686)
1 parent 344e4f3 commit f9f6444

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

libs/openFrameworks/utils/ofRandomDistributions.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,29 @@ namespace of::random {
1818

1919
template <typename T = float, typename... Args>
2020
std::enable_if_t<std::is_floating_point_v<T>, T>
21-
uniform(Args &&... args) {
22-
std::uniform_real_distribution<T> distr(std::forward<Args>(args)...);
21+
uniform(T max = 1.0) {
22+
std::uniform_real_distribution<T> distr(0, max);
2323
return distr(of::random::gen());
2424
}
2525

2626
template <typename T, typename... Args>
2727
std::enable_if_t<std::is_integral_v<T>, T>
28-
uniform(Args &&... args) {
29-
std::uniform_int_distribution<T> distr(std::forward<Args>(args)...);
28+
uniform(T max) {
29+
std::uniform_int_distribution<T> distr(0, max);
30+
return distr(of::random::gen());
31+
}
32+
33+
template <typename T = float, typename... Args>
34+
std::enable_if_t<std::is_floating_point_v<T>, T>
35+
uniform(T min, T max) {
36+
std::uniform_real_distribution<T> distr(min, max);
37+
return distr(of::random::gen());
38+
}
39+
40+
template <typename T, typename... Args>
41+
std::enable_if_t<std::is_integral_v<T>, T>
42+
uniform(T min, T max) {
43+
std::uniform_int_distribution<T> distr(min, max);
3044
return distr(of::random::gen());
3145
}
3246

0 commit comments

Comments
 (0)