diff options
author | Yuri Roubinsky <chaosus89@gmail.com> | 2020-07-26 13:52:24 +0300 |
---|---|---|
committer | Yuri Roubinsky <chaosus89@gmail.com> | 2020-11-06 17:06:26 +0300 |
commit | 38fb26794bcc4352c22e46b97408673cf7084c57 (patch) | |
tree | 6e17a5a21e4d8c9cd58f3b0e214e259e3ec0e679 /core/math/random_pcg.cpp | |
parent | df2abc55be9c8b9f419a1b99cbad94024d150a09 (diff) | |
download | redot-engine-38fb26794bcc4352c22e46b97408673cf7084c57.tar.gz |
Exposed randi_range to global funcs + renamed rand_range to randf_range
Diffstat (limited to 'core/math/random_pcg.cpp')
-rw-r--r-- | core/math/random_pcg.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp index 02257c38d9..e0768b9403 100644 --- a/core/math/random_pcg.cpp +++ b/core/math/random_pcg.cpp @@ -49,3 +49,18 @@ double RandomPCG::random(double p_from, double p_to) { float RandomPCG::random(float p_from, float p_to) { return randf() * (p_to - p_from) + p_from; } + +int RandomPCG::random(int p_from, int p_to) { + int range; + int min; + if (p_to > p_from) { + range = p_to - p_from + 1; + min = p_from; + } else if (p_to < p_from) { + range = p_from - p_to + 1; + min = p_to; + } else { // from == to + return p_from; + } + return rand(range) + min; +} |