Added integer number generation function to RNG class

This commit is contained in:
Chaosus 2018-12-03 17:43:14 +03:00
parent 8dd00ed176
commit d376be2bf4
3 changed files with 21 additions and 4 deletions

View File

@ -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);
}

View File

@ -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();
};

View File

@ -10,7 +10,7 @@
<demos>
</demos>
<methods>
<method name="rand_range">
<method name="randf_range">
<return type="float">
</return>
<argument index="0" name="from" type="float">
@ -21,6 +21,17 @@
Generates pseudo-random float between [code]from[/code] and [code]to[/code].
</description>
</method>
<method name="randi_range">
<return type="int">
</return>
<argument index="0" name="from" type="int">
</argument>
<argument index="1" name="to" type="int">
</argument>
<description>
Generates pseudo-random 32-bit signed integer between [code]from[/code] and [code]to[/code](inclusive).
</description>
</method>
<method name="randf">
<return type="float">
</return>
@ -32,7 +43,7 @@
<return type="int">
</return>
<description>
Generates pseudo-random 32-bit integer between '0' and '4294967295'.
Generates pseudo-random 32-bit unsigned integer between '0' and '4294967295'.
</description>
</method>
<method name="randomize">