Math.RandomRange bug?

thp314

Civil Gamers Expert
Feb 8, 2021
1
0
81
Not sure if this is the right place but found what appears to be a bug with Math.RandomRange. Please explain or fix.

C-like:
using Console;
using Math;
using Util;
using Application;

// Generate an integer between 1 and 20
number i = 0;
number randomNumberFloat;
number randomNumber;
while (i < 20) {
    randomNumberFloat = Math.RandomRange(19.9, 20);
    randomNumber = Math.Ceil(randomNumberFloat));
    if(randomNumber == 21){
        Console.WriteLine("random float:");
        Console.WriteLine(Util.ToString(randomNumberFloat));
        Console.WriteLine("ceiling number:");
        Console.WriteLine(Util.ToString(randomNumber));   
    }
    i = i+1;
}
```

output:
Code:
random float:
20.9
ceiling number:
21
random float:
20.9
ceiling number:
21

Note that when using Math.RandomRange(20, 20); this behavior (of max + 0.9) does not appear (it correctly returns 20). So behavior is at least inconsistent.

Btw, I discovered this, because the tutorial script at https://www.civilgamers.com/community/pages/mnscript/ surprised me by saying the secret number in a range of 1-20 was 21! (so pretty sure this is not intended behavior)