snozbot / fungus

An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
MIT License
1.6k stars 291 forks source link

Random Integer does not use the Max Value #944

Closed Ray2r closed 3 years ago

Ray2r commented 3 years ago

Describe the bug The Random Integer action does not use the Max Value integer inputted.

To Reproduce If Min Value = 1 and Max Value = 3. The Random Integer will only randomize between 1 and 2 but NOT 3.

Expected behavior The Random Integer should choose between 1, 2 and 3 not just 1 and 2.

Additional context I think the same applies to Random Float. But I cannot be certain as Random Float goes to 8 decimal places.

Arylos07 commented 3 years ago

The Random Integer command uses Unity's Random.Range() function which, when using integers, is exclusive, meaning it does not include the max value in the random. Floats are inclusive so the Random Float command should include the max value.

This is a standard behaviour of getting random numbers using Random.Range() with integers so it's not necessarily a bug and some code relies on this. For the sake of simplicity and consistency, adjusting the command may not be needed.

You could increase your max value to account for this, or alternatively change the Random Integer command so it uses maxValue.Value + 1 instead. This way, you can enter 3 and it should include that value.

Ray2r commented 3 years ago

Ahh, thanks for that @Arylos07.