mjansson / foundation_lib

Cross-platform public domain foundation library in C providing basic support data types and functions to write applications and games in a platform-independent fashion.
The Unlicense
301 stars 23 forks source link

random32_range(0, 1) doesn't return 1 #12

Closed ghost closed 9 years ago

ghost commented 9 years ago

As the title says, it doesn't return most high value.

mjansson commented 9 years ago

As designed, docs say "Generate 32 bit random number in [low,high) range" which should be read as low value is included in returned values while high value is excluded.

mjansson commented 9 years ago

Reasoning behind this is that a normal use case is to randomize an index into an array. You can then do random32_range(0, size), in which case you don't want to have size as a returned value since that would index outside the array.