diff options
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; +} |