diff --git a/CHANGELOG.md b/CHANGELOG.md index 4886a7796..a52c27641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed +- `random_range(min, max)` now returns a random integer between `min` and `max`, inclusive. (Previously, it returned a float.) +- Added a new function, `random_range_float` now returns a random float between `min` and `max`, inclusive. (This is the previous behaviour of `random_range`.) + ### Removed ## [2.4.2] 2024-02-24 diff --git a/YarnSpinner/Dialogue.cs b/YarnSpinner/Dialogue.cs index fe45b7ac9..fa71c19b3 100644 --- a/YarnSpinner/Dialogue.cs +++ b/YarnSpinner/Dialogue.cs @@ -1142,7 +1142,12 @@ public StandardLibrary() return Random.NextDouble(); }); - this.RegisterFunction("random_range", delegate (float minInclusive, float maxInclusive) + this.RegisterFunction("random_range", (float min, float max) => + { + return Random.Next((int)max - (int)min + 1) + min; + }); + + this.RegisterFunction("random_range_float", delegate (float minInclusive, float maxInclusive) { var t = Random.NextDouble(); return minInclusive + t * (maxInclusive - minInclusive);