We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 051712d + 1089f61 commit 075b550Copy full SHA for 075b550
core/math/random_pcg.cpp
@@ -80,5 +80,15 @@ int RandomPCG::random(int p_from, int p_to) {
80
if (p_from == p_to) {
81
return p_from;
82
}
83
- return int(rand(uint32_t(Math::abs(p_from - p_to)) + 1U)) + MIN(p_from, p_to);
+
84
+ int64_t min = MIN(p_from, p_to);
85
+ int64_t max = MAX(p_from, p_to);
86
+ uint32_t diff = static_cast<uint32_t>(max - min);
87
88
+ if (diff == UINT32_MAX) {
89
+ // Can't add 1 to max uint32_t value for inclusive range, so call rand without passing bounds.
90
+ return static_cast<int64_t>(rand()) + min;
91
+ }
92
93
+ return static_cast<int64_t>(rand(diff + 1U)) + min;
94
0 commit comments