From e598f3abb930b8b520fd404c4719b39c921817ad Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Fri, 10 Apr 2026 02:44:49 +0200 Subject: [PATCH] Improve `RandomNumberGenerator.rand_weighted()` description in the class reference --- doc/classes/RandomNumberGenerator.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/classes/RandomNumberGenerator.xml b/doc/classes/RandomNumberGenerator.xml index 2d873a774d..3b53a82a9e 100644 --- a/doc/classes/RandomNumberGenerator.xml +++ b/doc/classes/RandomNumberGenerator.xml @@ -21,7 +21,9 @@ - Returns a random index with non-uniform weights. Prints an error and returns [code]-1[/code] if the array is empty. + Returns a random integer between [code]0[/code] and the size of the array that is passed as a parameter. Each value in the array should be a floating-point number that represents the relative likelihood that it will be returned as an index. A higher value means the value is more likely to be returned as an index, while a value of [code]0[/code] means it will never be returned as an index. + For example, if [code skip-lint][0.5, 1, 1, 2][/code] is passed as a parameter, then the method is twice as likely to return [code]3[/code] (the index of the value [code]2[/code]) and twice as unlikely to return [code]0[/code] (the index of the value [code]0.5[/code]) compared to the indices [code]1[/code] and [code]2[/code]. + Prints an error and returns [code]-1[/code] if the array is empty. [codeblocks] [gdscript] var rng = RandomNumberGenerator.new()