summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2024-03-02 15:34:51 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2024-03-02 20:56:01 -0600
commit981883d041f6e316cb88c4411e9b140192a9da5e (patch)
treefcea9cb247535599ba07105d4272dab767e4a6c7
parentf2045ba822bff7d34964901393581a3117c394a9 (diff)
downloadredot-engine-981883d041f6e316cb88c4411e9b140192a9da5e.tar.gz
Fix `RandomNumberGenerator::rand_weighted` return type
-rw-r--r--core/math/random_number_generator.h2
-rw-r--r--core/math/random_pcg.cpp2
-rw-r--r--core/math/random_pcg.h2
-rw-r--r--doc/classes/RandomNumberGenerator.xml6
4 files changed, 6 insertions, 6 deletions
diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h
index bedeb56ce4..7ec4cdffb0 100644
--- a/core/math/random_number_generator.h
+++ b/core/math/random_number_generator.h
@@ -57,7 +57,7 @@ public:
_FORCE_INLINE_ real_t randfn(real_t p_mean = 0.0, real_t p_deviation = 1.0) { return randbase.randfn(p_mean, p_deviation); }
_FORCE_INLINE_ int randi_range(int p_from, int p_to) { return randbase.random(p_from, p_to); }
- _FORCE_INLINE_ int rand_weighted(const Vector<float> &p_weights) { return randbase.rand_weighted(p_weights); }
+ _FORCE_INLINE_ int64_t rand_weighted(const Vector<float> &p_weights) { return randbase.rand_weighted(p_weights); }
RandomNumberGenerator() { randbase.randomize(); }
};
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp
index e754a34271..e083820494 100644
--- a/core/math/random_pcg.cpp
+++ b/core/math/random_pcg.cpp
@@ -43,7 +43,7 @@ void RandomPCG::randomize() {
seed(((uint64_t)OS::get_singleton()->get_unix_time() + OS::get_singleton()->get_ticks_usec()) * pcg.state + PCG_DEFAULT_INC_64);
}
-int RandomPCG::rand_weighted(const Vector<float> &p_weights) {
+int64_t RandomPCG::rand_weighted(const Vector<float> &p_weights) {
ERR_FAIL_COND_V_MSG(p_weights.is_empty(), -1, "Weights array is empty.");
int64_t weights_size = p_weights.size();
const float *weights = p_weights.ptr();
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h
index fa8ad3cfb3..fd0934b24a 100644
--- a/core/math/random_pcg.h
+++ b/core/math/random_pcg.h
@@ -90,7 +90,7 @@ public:
return pcg32_boundedrand_r(&pcg, bounds);
}
- int rand_weighted(const Vector<float> &p_weights);
+ int64_t rand_weighted(const Vector<float> &p_weights);
// Obtaining floating point numbers in [0, 1] range with "good enough" uniformity.
// These functions sample the output of rand() as the fraction part of an infinite binary number,
diff --git a/doc/classes/RandomNumberGenerator.xml b/doc/classes/RandomNumberGenerator.xml
index e005c1c22c..44e29d2322 100644
--- a/doc/classes/RandomNumberGenerator.xml
+++ b/doc/classes/RandomNumberGenerator.xml
@@ -24,13 +24,13 @@
Returns a random index with non-uniform weights. Prints an error and returns [code]-1[/code] if the array is empty.
[codeblocks]
[gdscript]
- var rnd = RandomNumberGenerator.new()
+ var rng = RandomNumberGenerator.new()
- var my_array = ["one", "two", "three, "four"]
+ var my_array = ["one", "two", "three", "four"]
var weights = PackedFloat32Array([0.5, 1, 1, 2])
# Prints one of the four elements in `my_array`.
- # It is more likely to print "four", and less likely to print "two".
+ # It is more likely to print "four", and less likely to print "one".
print(my_array[rng.rand_weighted(weights)])
[/gdscript]
[/codeblocks]