chrisyarbrough / SharpShuffleBag

An efficient shuffle bag implementation in C# - for .NET and Unity projects.
MIT License
5 stars 1 forks source link

Make implicit behaviour of Random.Range more clear #1

Closed chrisyarbrough closed 9 months ago

chrisyarbrough commented 9 months ago

UnityEngine.Random.Range and System.Random.Next both return a random int between min and maxExclusive. However, for the special case that min == max, min is returned. This is slightly inconsistent because it conflicts with the definition of exclusive. However, it's actually very convenient, because it makes the bag work with a single item. This use case could happen during development where the bag is supplied with a stand-in collection that only contains a single item, for example.

There's no real problem here, but maybe we can make it more clear, what the IRandomRangeSource interface is expected to return or implement some tests to solidify this. Potentially, it also makes sense to catch this condition in the ShuffleBag.Next function directly, because we don't have control over custom user implementation of IRandomRangeSource.

chrisyarbrough commented 9 months ago

Done in release 1.0.2