Skip to content

Commit

Permalink
Add random_range_float; make random_range consistent with YS3's behav…
Browse files Browse the repository at this point in the history
…iour.

Fixes #389.
  • Loading branch information
desplesda committed Dec 12, 2024
1 parent d52d3b7 commit 0fca50f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion YarnSpinner/Dialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0fca50f

Please sign in to comment.