diff --git a/core/math/random_number_generator.cpp b/core/math/random_number_generator.cpp
index e4ec0dac997..9f0a5bc992f 100644
--- a/core/math/random_number_generator.cpp
+++ b/core/math/random_number_generator.cpp
@@ -40,6 +40,7 @@ void RandomNumberGenerator::_bind_methods() {
ClassDB::bind_method(D_METHOD("randi"), &RandomNumberGenerator::randi);
ClassDB::bind_method(D_METHOD("randf"), &RandomNumberGenerator::randf);
- ClassDB::bind_method(D_METHOD("rand_range", "from", "to"), &RandomNumberGenerator::rand_range);
+ ClassDB::bind_method(D_METHOD("randf_range", "from", "to"), &RandomNumberGenerator::randf_range);
+ ClassDB::bind_method(D_METHOD("randi_range", "from", "to"), &RandomNumberGenerator::randi_range);
ClassDB::bind_method(D_METHOD("randomize"), &RandomNumberGenerator::randomize);
}
diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h
index 557863fdbdf..078bfbed60d 100644
--- a/core/math/random_number_generator.h
+++ b/core/math/random_number_generator.h
@@ -53,7 +53,12 @@ public:
_FORCE_INLINE_ real_t randf() { return randbase.randf(); }
- _FORCE_INLINE_ real_t rand_range(real_t from, real_t to) { return randbase.random(from, to); }
+ _FORCE_INLINE_ real_t randf_range(real_t from, real_t to) { return randbase.random(from, to); }
+
+ _FORCE_INLINE_ int randi_range(int from, int to) {
+ unsigned int ret = randbase.rand();
+ return ret % (to - from + 1) + from;
+ }
RandomNumberGenerator();
};
diff --git a/doc/classes/RandomNumberGenerator.xml b/doc/classes/RandomNumberGenerator.xml
index aee9654561a..720acc16ba9 100644
--- a/doc/classes/RandomNumberGenerator.xml
+++ b/doc/classes/RandomNumberGenerator.xml
@@ -10,7 +10,7 @@
-
+
@@ -21,6 +21,17 @@
Generates pseudo-random float between [code]from[/code] and [code]to[/code].
+
+
+
+
+
+
+
+
+ Generates pseudo-random 32-bit signed integer between [code]from[/code] and [code]to[/code](inclusive).
+
+
@@ -32,7 +43,7 @@
- Generates pseudo-random 32-bit integer between '0' and '4294967295'.
+ Generates pseudo-random 32-bit unsigned integer between '0' and '4294967295'.