diff --git a/docs/api_reference.md b/docs/api_reference.md index 23dcbcce3..04ebfbb91 100644 --- a/docs/api_reference.md +++ b/docs/api_reference.md @@ -1199,18 +1199,18 @@ This is a list of all functions in Cute Framework organized by categories. This ## random ### functions -- [cf_rnd_next](/random/cf_rnd_next.md) -- [cf_rnd_next_double](/random/cf_rnd_next_double.md) -- [cf_rnd_next_float](/random/cf_rnd_next_float.md) -- [cf_rnd_next_range_double](/random/cf_rnd_next_range_double.md) -- [cf_rnd_next_range_float](/random/cf_rnd_next_range_float.md) -- [cf_rnd_next_range_int](/random/cf_rnd_next_range_int.md) -- [cf_rnd_next_range_uint64](/random/cf_rnd_next_range_uint64.md) +- [cf_rnd](/random/cf_rnd.md) +- [cf_rnd_double](/random/cf_rnd_double.md) +- [cf_rnd_float](/random/cf_rnd_float.md) +- [cf_rnd_range_double](/random/cf_rnd_range_double.md) +- [cf_rnd_range_float](/random/cf_rnd_range_float.md) +- [cf_rnd_range_int](/random/cf_rnd_range_int.md) +- [cf_rnd_range_uint64](/random/cf_rnd_range_uint64.md) - [cf_rnd_seed](/random/cf_rnd_seed.md) ### structs -- [CF_Rnd](/random/cf_rnd.md) +- [CF_RndState](/random/cf_rndstate.md) ## sprite diff --git a/docs/random/cf_rnd.md b/docs/random/cf_rnd.md index 04216c021..c4cc48753 100644 --- a/docs/random/cf_rnd.md +++ b/docs/random/cf_rnd.md @@ -1,28 +1,28 @@ [](../header.md ':include') -# CF_Rnd +# cf_rnd Category: [random](/api_reference?id=random) GitHub: [cute_rnd.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_rnd.h) --- -A random number generator. +Returns a random `uint64_t`. -Struct Members | Description ---- | --- -`uint64_t state[2]` | Just two `uint64_t`'s for the internal state. Very small! These are setup by [cf_rnd_seed](/random/cf_rnd_seed.md). - -## Remarks +```cpp +uint64_t cf_rnd(CF_RndState* rnd); +``` -A random number generator of the type LFSR (linear feedback shift registers). This specific -implementation uses the XorShift+ variation, and returns 64-bit random numbers. More information -can be found on Wikipedia. -https://en.wikipedia.org/wiki/Xorshift - -This implementation comes from Mattias Gustavsson's single-file header collection. -https://github.com/mattiasgustavsson/libs/blob/main/rnd.h +Parameters | Description +--- | --- +rnd | The random number generator state. ## Related Pages -[cf_rnd_next](/random/cf_rnd_next.md) +[CF_RndState](/random/cf_rndstate.md) [cf_rnd_seed](/random/cf_rnd_seed.md) +[cf_rnd_range_double](/random/cf_rnd_range_double.md) +[cf_rnd_float](/random/cf_rnd_float.md) +[cf_rnd_double](/random/cf_rnd_double.md) +[cf_rnd_range_int](/random/cf_rnd_range_int.md) +[cf_rnd_range_uint64](/random/cf_rnd_range_uint64.md) +[cf_rnd_range_float](/random/cf_rnd_range_float.md) diff --git a/docs/random/cf_rnd_double.md b/docs/random/cf_rnd_double.md new file mode 100644 index 000000000..54a481a93 --- /dev/null +++ b/docs/random/cf_rnd_double.md @@ -0,0 +1,28 @@ +[](../header.md ':include') + +# cf_rnd_double + +Category: [random](/api_reference?id=random) +GitHub: [cute_rnd.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_rnd.h) +--- + +Returns a random `double`. + +```cpp +double cf_rnd_double(CF_RndState* rnd); +``` + +Parameters | Description +--- | --- +rnd | The random number generator state. + +## Related Pages + +[CF_RndState](/random/cf_rndstate.md) +[cf_rnd_seed](/random/cf_rnd_seed.md) +[cf_rnd](/random/cf_rnd.md) +[cf_rnd_float](/random/cf_rnd_float.md) +[cf_rnd_range_double](/random/cf_rnd_range_double.md) +[cf_rnd_range_int](/random/cf_rnd_range_int.md) +[cf_rnd_range_uint64](/random/cf_rnd_range_uint64.md) +[cf_rnd_range_float](/random/cf_rnd_range_float.md) diff --git a/docs/random/cf_rnd_float.md b/docs/random/cf_rnd_float.md new file mode 100644 index 000000000..e42ea8ce9 --- /dev/null +++ b/docs/random/cf_rnd_float.md @@ -0,0 +1,28 @@ +[](../header.md ':include') + +# cf_rnd_float + +Category: [random](/api_reference?id=random) +GitHub: [cute_rnd.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_rnd.h) +--- + +Returns a random `float`. + +```cpp +float cf_rnd_float(CF_RndState* rnd); +``` + +Parameters | Description +--- | --- +rnd | The random number generator state. + +## Related Pages + +[CF_RndState](/random/cf_rndstate.md) +[cf_rnd_seed](/random/cf_rnd_seed.md) +[cf_rnd](/random/cf_rnd.md) +[cf_rnd_range_double](/random/cf_rnd_range_double.md) +[cf_rnd_double](/random/cf_rnd_double.md) +[cf_rnd_range_int](/random/cf_rnd_range_int.md) +[cf_rnd_range_uint64](/random/cf_rnd_range_uint64.md) +[cf_rnd_range_float](/random/cf_rnd_range_float.md) diff --git a/docs/random/cf_rnd_range_double.md b/docs/random/cf_rnd_range_double.md new file mode 100644 index 000000000..ea0d0c749 --- /dev/null +++ b/docs/random/cf_rnd_range_double.md @@ -0,0 +1,28 @@ +[](../header.md ':include') + +# cf_rnd_range_double + +Category: [random](/api_reference?id=random) +GitHub: [cute_rnd.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_rnd.h) +--- + +Returns a random `double` from the range `min` to `max` (inclusive). + +```cpp +double cf_rnd_range_double(CF_RndState* rnd, double min, double max); +``` + +Parameters | Description +--- | --- +rnd | The random number generator state. + +## Related Pages + +[CF_RndState](/random/cf_rndstate.md) +[cf_rnd_seed](/random/cf_rnd_seed.md) +[cf_rnd](/random/cf_rnd.md) +[cf_rnd_float](/random/cf_rnd_float.md) +[cf_rnd_double](/random/cf_rnd_double.md) +[cf_rnd_range_int](/random/cf_rnd_range_int.md) +[cf_rnd_range_uint64](/random/cf_rnd_range_uint64.md) +[cf_rnd_range_float](/random/cf_rnd_range_float.md) diff --git a/docs/random/cf_rnd_range_float.md b/docs/random/cf_rnd_range_float.md new file mode 100644 index 000000000..f63a28c81 --- /dev/null +++ b/docs/random/cf_rnd_range_float.md @@ -0,0 +1,28 @@ +[](../header.md ':include') + +# cf_rnd_range_float + +Category: [random](/api_reference?id=random) +GitHub: [cute_rnd.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_rnd.h) +--- + +Returns a random `float` from the range `min` to `max` (inclusive). + +```cpp +float cf_rnd_range_float(CF_RndState* rnd, float min, float max); +``` + +Parameters | Description +--- | --- +rnd | The random number generator state. + +## Related Pages + +[CF_RndState](/random/cf_rndstate.md) +[cf_rnd_seed](/random/cf_rnd_seed.md) +[cf_rnd](/random/cf_rnd.md) +[cf_rnd_float](/random/cf_rnd_float.md) +[cf_rnd_double](/random/cf_rnd_double.md) +[cf_rnd_range_int](/random/cf_rnd_range_int.md) +[cf_rnd_range_uint64](/random/cf_rnd_range_uint64.md) +[cf_rnd_range_double](/random/cf_rnd_range_double.md) diff --git a/docs/random/cf_rnd_range_int.md b/docs/random/cf_rnd_range_int.md new file mode 100644 index 000000000..33e8a60cf --- /dev/null +++ b/docs/random/cf_rnd_range_int.md @@ -0,0 +1,28 @@ +[](../header.md ':include') + +# cf_rnd_range_int + +Category: [random](/api_reference?id=random) +GitHub: [cute_rnd.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_rnd.h) +--- + +Returns a random `int` from the range `min` to `max` (inclusive). + +```cpp +int cf_rnd_range_int(CF_RndState* rnd, int min, int max); +``` + +Parameters | Description +--- | --- +rnd | The random number generator state. + +## Related Pages + +[CF_RndState](/random/cf_rndstate.md) +[cf_rnd_seed](/random/cf_rnd_seed.md) +[cf_rnd](/random/cf_rnd.md) +[cf_rnd_float](/random/cf_rnd_float.md) +[cf_rnd_double](/random/cf_rnd_double.md) +[cf_rnd_range_double](/random/cf_rnd_range_double.md) +[cf_rnd_range_uint64](/random/cf_rnd_range_uint64.md) +[cf_rnd_range_float](/random/cf_rnd_range_float.md) diff --git a/docs/random/cf_rnd_range_uint64.md b/docs/random/cf_rnd_range_uint64.md new file mode 100644 index 000000000..e0c3c2c8c --- /dev/null +++ b/docs/random/cf_rnd_range_uint64.md @@ -0,0 +1,28 @@ +[](../header.md ':include') + +# cf_rnd_range_uint64 + +Category: [random](/api_reference?id=random) +GitHub: [cute_rnd.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_rnd.h) +--- + +Returns a random `uint64_t` from the range `min` to `max` (inclusive). + +```cpp +uint64_t cf_rnd_range_uint64(CF_RndState* rnd, uint64_t min, uint64_t max); +``` + +Parameters | Description +--- | --- +rnd | The random number generator state. + +## Related Pages + +[CF_RndState](/random/cf_rndstate.md) +[cf_rnd_seed](/random/cf_rnd_seed.md) +[cf_rnd](/random/cf_rnd.md) +[cf_rnd_float](/random/cf_rnd_float.md) +[cf_rnd_double](/random/cf_rnd_double.md) +[cf_rnd_range_int](/random/cf_rnd_range_int.md) +[cf_rnd_range_double](/random/cf_rnd_range_double.md) +[cf_rnd_range_float](/random/cf_rnd_range_float.md) diff --git a/docs/random/cf_rnd_seed.md b/docs/random/cf_rnd_seed.md index b10c05940..c3407d620 100644 --- a/docs/random/cf_rnd_seed.md +++ b/docs/random/cf_rnd_seed.md @@ -9,7 +9,7 @@ GitHub: [cute_rnd.h](https://github.com/RandyGaul/cute_framework/blob/master/inc Returns an initialized [CF_Rnd](/random/cf_rnd.md) based on an initial `seed` value. ```cpp -CF_Rnd cf_rnd_seed(uint64_t seed); +CF_RndState cf_rnd_seed(uint64_t seed); ``` Parameters | Description @@ -23,5 +23,5 @@ deterministic way, so it's often important for many games to control or note whi ## Related Pages -[CF_Rnd](/random/cf_rnd.md) -[cf_rnd_next](/random/cf_rnd_next.md) +[CF_RndState](/random/cf_rndstate.md) +[cf_rnd](/random/cf_rnd.md) diff --git a/docs/random/cf_rndstate.md b/docs/random/cf_rndstate.md new file mode 100644 index 000000000..1fbc7d174 --- /dev/null +++ b/docs/random/cf_rndstate.md @@ -0,0 +1,28 @@ +[](../header.md ':include') + +# CF_RndState + +Category: [random](/api_reference?id=random) +GitHub: [cute_rnd.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_rnd.h) +--- + +A random number generator. + +Struct Members | Description +--- | --- +`uint64_t state[2]` | Just two `uint64_t`'s for the internal state. Very small! These are setup by [cf_rnd_seed](/random/cf_rnd_seed.md). + +## Remarks + +A random number generator of the type LFSR (linear feedback shift registers). This specific +implementation uses the XorShift+ variation, and returns 64-bit random numbers. More information +can be found on Wikipedia. +https://en.wikipedia.org/wiki/Xorshift + +This implementation comes from Mattias Gustavsson's single-file header collection. +https://github.com/mattiasgustavsson/libs/blob/main/rnd.h + +## Related Pages + +[cf_rnd](/random/cf_rnd.md) +[cf_rnd_seed](/random/cf_rnd_seed.md) diff --git a/include/cute_rnd.h b/include/cute_rnd.h index 21d4c456e..48a52d936 100644 --- a/include/cute_rnd.h +++ b/include/cute_rnd.h @@ -18,7 +18,7 @@ extern "C" { #endif // __cplusplus /** - * @struct CF_Rnd + * @struct CF_RndState * @category random * @brief A random number generator. * @remarks A random number generator of the type LFSR (linear feedback shift registers). This specific @@ -28,13 +28,13 @@ extern "C" { * * This implementation comes from Mattias Gustavsson's single-file header collection. * https://github.com/mattiasgustavsson/libs/blob/main/rnd.h - * @related CF_Rnd cf_rnd_seed cf_rnd_next + * @related CF_RndState cf_rnd_seed cf_rnd */ -typedef struct CF_Rnd +typedef struct CF_RndState { /* @member Just two `uint64_t`'s for the internal state. Very small! These are setup by `cf_rnd_seed`. */ uint64_t state[2]; -} CF_Rnd; +} CF_RndState; // @end /** @@ -44,72 +44,72 @@ typedef struct CF_Rnd * @param seed The initial seed value for the random number generator. * @remarks The `seed` is used to control which set of random numbers get generated. The numbers are generated in a completely * deterministic way, so it's often important for many games to control or note which seed is used. - * @related CF_Rnd cf_rnd_seed cf_rnd_next + * @related CF_RndState cf_rnd_seed cf_rnd */ -CF_INLINE CF_Rnd CF_CALL cf_rnd_seed(uint64_t seed); +CF_INLINE CF_RndState CF_CALL cf_rnd_seed(uint64_t seed); /** - * @function cf_rnd_next + * @function cf_rnd * @category random * @brief Returns a random `uint64_t`. * @param rnd The random number generator state. - * @related CF_Rnd cf_rnd_seed cf_rnd_next cf_rnd_next_float cf_rnd_next_double cf_rnd_next_range_int cf_rnd_next_range_uint64 cf_rnd_next_range_float cf_rnd_next_range_double + * @related CF_RndState cf_rnd_seed cf_rnd cf_rnd_float cf_rnd_double cf_rnd_range_int cf_rnd_range_uint64 cf_rnd_range_float cf_rnd_range_double */ -CF_INLINE uint64_t CF_CALL cf_rnd_next(CF_Rnd* rnd); +CF_INLINE uint64_t CF_CALL cf_rnd(CF_RndState* rnd); /** - * @function cf_rnd_next_float + * @function cf_rnd_float * @category random * @brief Returns a random `float`. * @param rnd The random number generator state. - * @related CF_Rnd cf_rnd_seed cf_rnd_next cf_rnd_next_float cf_rnd_next_double cf_rnd_next_range_int cf_rnd_next_range_uint64 cf_rnd_next_range_float cf_rnd_next_range_double + * @related CF_RndState cf_rnd_seed cf_rnd cf_rnd_float cf_rnd_double cf_rnd_range_int cf_rnd_range_uint64 cf_rnd_range_float cf_rnd_range_double */ -CF_INLINE float CF_CALL cf_rnd_next_float(CF_Rnd* rnd); +CF_INLINE float CF_CALL cf_rnd_float(CF_RndState* rnd); /** - * @function cf_rnd_next_double + * @function cf_rnd_double * @category random * @brief Returns a random `double`. * @param rnd The random number generator state. - * @related CF_Rnd cf_rnd_seed cf_rnd_next cf_rnd_next_float cf_rnd_next_double cf_rnd_next_range_int cf_rnd_next_range_uint64 cf_rnd_next_range_float cf_rnd_next_range_double + * @related CF_RndState cf_rnd_seed cf_rnd cf_rnd_float cf_rnd_double cf_rnd_range_int cf_rnd_range_uint64 cf_rnd_range_float cf_rnd_range_double */ -CF_INLINE double CF_CALL cf_rnd_next_double(CF_Rnd* rnd); +CF_INLINE double CF_CALL cf_rnd_double(CF_RndState* rnd); /** - * @function cf_rnd_next_range_int + * @function cf_rnd_range_int * @category random * @brief Returns a random `int` from the range `min` to `max` (inclusive). * @param rnd The random number generator state. - * @related CF_Rnd cf_rnd_seed cf_rnd_next cf_rnd_next_float cf_rnd_next_double cf_rnd_next_range_int cf_rnd_next_range_uint64 cf_rnd_next_range_float cf_rnd_next_range_double + * @related CF_RndState cf_rnd_seed cf_rnd cf_rnd_float cf_rnd_double cf_rnd_range_int cf_rnd_range_uint64 cf_rnd_range_float cf_rnd_range_double */ -CF_INLINE int CF_CALL cf_rnd_next_range_int(CF_Rnd* rnd, int min, int max); +CF_INLINE int CF_CALL cf_rnd_range_int(CF_RndState* rnd, int min, int max); /** - * @function cf_rnd_next_range_uint64 + * @function cf_rnd_range_uint64 * @category random * @brief Returns a random `uint64_t` from the range `min` to `max` (inclusive). * @param rnd The random number generator state. - * @related CF_Rnd cf_rnd_seed cf_rnd_next cf_rnd_next_float cf_rnd_next_double cf_rnd_next_range_int cf_rnd_next_range_uint64 cf_rnd_next_range_float cf_rnd_next_range_double + * @related CF_RndState cf_rnd_seed cf_rnd cf_rnd_float cf_rnd_double cf_rnd_range_int cf_rnd_range_uint64 cf_rnd_range_float cf_rnd_range_double */ -CF_INLINE uint64_t CF_CALL cf_rnd_next_range_uint64(CF_Rnd* rnd, uint64_t min, uint64_t max); +CF_INLINE uint64_t CF_CALL cf_rnd_range_uint64(CF_RndState* rnd, uint64_t min, uint64_t max); /** - * @function cf_rnd_next_range_float + * @function cf_rnd_range_float * @category random * @brief Returns a random `float` from the range `min` to `max` (inclusive). * @param rnd The random number generator state. - * @related CF_Rnd cf_rnd_seed cf_rnd_next cf_rnd_next_float cf_rnd_next_double cf_rnd_next_range_int cf_rnd_next_range_uint64 cf_rnd_next_range_float cf_rnd_next_range_double + * @related CF_RndState cf_rnd_seed cf_rnd cf_rnd_float cf_rnd_double cf_rnd_range_int cf_rnd_range_uint64 cf_rnd_range_float cf_rnd_range_double */ -CF_INLINE float CF_CALL cf_rnd_next_range_float(CF_Rnd* rnd, float min, float max); +CF_INLINE float CF_CALL cf_rnd_range_float(CF_RndState* rnd, float min, float max); /** - * @function cf_rnd_next_range_double + * @function cf_rnd_range_double * @category random * @brief Returns a random `double` from the range `min` to `max` (inclusive). * @param rnd The random number generator state. - * @related CF_Rnd cf_rnd_seed cf_rnd_next cf_rnd_next_float cf_rnd_next_double cf_rnd_next_range_int cf_rnd_next_range_uint64 cf_rnd_next_range_float cf_rnd_next_range_double + * @related CF_RndState cf_rnd_seed cf_rnd cf_rnd_float cf_rnd_double cf_rnd_range_int cf_rnd_range_uint64 cf_rnd_range_float cf_rnd_range_double */ -CF_INLINE double CF_CALL cf_rnd_next_range_double(CF_Rnd* rnd, double min, double max); +CF_INLINE double CF_CALL cf_rnd_range_double(CF_RndState* rnd, double min, double max); // ------------------------------------------------------------------------------------------------- @@ -123,16 +123,16 @@ CF_INLINE uint64_t cf_internal_rnd_murmur3_avalanche64(uint64_t h) return h; } -CF_INLINE CF_Rnd cf_rnd_seed(uint64_t seed) +CF_INLINE CF_RndState cf_rnd_seed(uint64_t seed) { - CF_Rnd rnd; + CF_RndState rnd; uint64_t value = cf_internal_rnd_murmur3_avalanche64((seed << 1ULL) | 1ULL); rnd.state[0] = value; rnd.state[1] = cf_internal_rnd_murmur3_avalanche64(value); return rnd; } -CF_INLINE uint64_t cf_rnd_next(CF_Rnd* rnd) +CF_INLINE uint64_t cf_rnd(CF_RndState* rnd) { uint64_t x = rnd->state[0]; uint64_t y = rnd->state[1]; @@ -144,9 +144,9 @@ CF_INLINE uint64_t cf_rnd_next(CF_Rnd* rnd) return x + y; } -CF_INLINE float cf_rnd_next_float(CF_Rnd* rnd) +CF_INLINE float cf_rnd_float(CF_RndState* rnd) { - uint32_t value = (uint32_t)(cf_rnd_next(rnd) >> 32); + uint32_t value = (uint32_t)(cf_rnd(rnd) >> 32); // Convert a randomized uint32_t value to a float value x in the range 0.0f <= x < 1.0f. // Contributed by Jonatan Hedborg. @@ -156,40 +156,40 @@ CF_INLINE float cf_rnd_next_float(CF_Rnd* rnd) return *(float*)&result - 1.0f; } -CF_INLINE double cf_rnd_next_double(CF_Rnd* rnd) +CF_INLINE double cf_rnd_double(CF_RndState* rnd) { - uint64_t value = cf_rnd_next(rnd); + uint64_t value = cf_rnd(rnd); uint64_t exponent = 1023; uint64_t mantissa = value >> 12; uint64_t result = (exponent << 52) | mantissa; return *(double*)&result - 1.0; } -CF_INLINE int cf_rnd_next_range_int(CF_Rnd* rnd, int min, int max) +CF_INLINE int cf_rnd_range_int(CF_RndState* rnd, int min, int max) { int range = (max - min) + 1; - int value = (int)(cf_rnd_next(rnd) % range); + int value = (int)(cf_rnd(rnd) % range); return min + value; } -CF_INLINE uint64_t cf_rnd_next_range_uint64(CF_Rnd* rnd, uint64_t min, uint64_t max) +CF_INLINE uint64_t cf_rnd_range_uint64(CF_RndState* rnd, uint64_t min, uint64_t max) { uint64_t range = (max - min) + 1; - uint64_t value = cf_rnd_next(rnd) % range; + uint64_t value = cf_rnd(rnd) % range; return min + value; } -CF_INLINE float cf_rnd_next_range_float(CF_Rnd* rnd, float min, float max) +CF_INLINE float cf_rnd_range_float(CF_RndState* rnd, float min, float max) { float range = max - min; - float value = cf_rnd_next_float(rnd) * range; + float value = cf_rnd_float(rnd) * range; return min + value; } -CF_INLINE double cf_rnd_next_range_double(CF_Rnd* rnd, double min, double max) +CF_INLINE double cf_rnd_range_double(CF_RndState* rnd, double min, double max) { double range = max - min; - double value = cf_rnd_next_float(rnd) * range; + double value = cf_rnd_float(rnd) * range; return min + value; } @@ -205,7 +205,7 @@ CF_INLINE double cf_rnd_next_range_double(CF_Rnd* rnd, double min, double max) namespace Cute { -using Rnd = CF_Rnd; +using Rnd = CF_RndState; namespace internal { @@ -215,21 +215,21 @@ CF_INLINE uint64_t rnd_murmur3_avalanche64(uint64_t h) { return cf_internal_rnd_ } CF_INLINE Rnd rnd_seed(uint64_t seed) { return cf_rnd_seed(seed); } -CF_INLINE uint64_t rnd_next(Rnd* rnd) { return cf_rnd_next(rnd); } -CF_INLINE float rnd_next_float(Rnd* rnd) { return cf_rnd_next_float(rnd); } -CF_INLINE double rnd_next_double(Rnd* rnd) { return cf_rnd_next_double(rnd); } -CF_INLINE int rnd_next_range(Rnd* rnd, int min, int max) { return cf_rnd_next_range_int(rnd, min, max); } -CF_INLINE uint64_t rnd_next_range(Rnd* rnd, uint64_t min, uint64_t max) { return cf_rnd_next_range_uint64(rnd, min, max); } -CF_INLINE float rnd_next_range(Rnd* rnd, float min, float max) { return cf_rnd_next_range_float(rnd, min, max); } -CF_INLINE double rnd_next_range(Rnd* rnd, double min, double max) { return cf_rnd_next_range_double(rnd, min, max); } - -CF_INLINE uint64_t rnd_next(Rnd& rnd) { return cf_rnd_next(&rnd); } -CF_INLINE float rnd_next_float(Rnd& rnd) { return cf_rnd_next_float(&rnd); } -CF_INLINE double rnd_next_double(Rnd& rnd) { return cf_rnd_next_double(&rnd); } -CF_INLINE int rnd_next_range(Rnd& rnd, int min, int max) { return cf_rnd_next_range_int(&rnd, min, max); } -CF_INLINE uint64_t rnd_next_range(Rnd& rnd, uint64_t min, uint64_t max) { return cf_rnd_next_range_uint64(&rnd, min, max); } -CF_INLINE float rnd_next_range(Rnd& rnd, float min, float max) { return cf_rnd_next_range_float(&rnd, min, max); } -CF_INLINE double rnd_next_range(Rnd& rnd, double min, double max) { return cf_rnd_next_range_double(&rnd, min, max); } +CF_INLINE uint64_t rnd(Rnd* rnd) { return cf_rnd(rnd); } +CF_INLINE float rnd_float(Rnd* rnd) { return cf_rnd_float(rnd); } +CF_INLINE double rnd_double(Rnd* rnd) { return cf_rnd_double(rnd); } +CF_INLINE int rnd_range(Rnd* rnd, int min, int max) { return cf_rnd_range_int(rnd, min, max); } +CF_INLINE uint64_t rnd_range(Rnd* rnd, uint64_t min, uint64_t max) { return cf_rnd_range_uint64(rnd, min, max); } +CF_INLINE float rnd_range(Rnd* rnd, float min, float max) { return cf_rnd_range_float(rnd, min, max); } +CF_INLINE double rnd_range(Rnd* rnd, double min, double max) { return cf_rnd_range_double(rnd, min, max); } + +CF_INLINE uint64_t rnd(Rnd& rnd) { return cf_rnd(&rnd); } +CF_INLINE float rnd_float(Rnd& rnd) { return cf_rnd_float(&rnd); } +CF_INLINE double rnd_double(Rnd& rnd) { return cf_rnd_double(&rnd); } +CF_INLINE int rnd_range(Rnd& rnd, int min, int max) { return cf_rnd_range_int(&rnd, min, max); } +CF_INLINE uint64_t rnd_range(Rnd& rnd, uint64_t min, uint64_t max) { return cf_rnd_range_uint64(&rnd, min, max); } +CF_INLINE float rnd_range(Rnd& rnd, float min, float max) { return cf_rnd_range_float(&rnd, min, max); } +CF_INLINE double rnd_range(Rnd& rnd, double min, double max) { return cf_rnd_range_double(&rnd, min, max); } } diff --git a/samples/scratch.cpp b/samples/scratch.cpp index a5edb4fb2..5cae51732 100644 --- a/samples/scratch.cpp +++ b/samples/scratch.cpp @@ -152,7 +152,7 @@ int main(int argc, char* argv[]) }; Rnd rnd = rnd_seed(0); for (int i = 0; i < CF_ARRAY_SIZE(pts); ++i) { - auto f = [&](float s) { return rnd_next_range(rnd, 1.0f, 3.0f) * s; }; + auto f = [&](float s) { return rnd_range(rnd, 1.0f, 3.0f) * s; }; if (i%2) { pts[i] += V2(cosf(t*f(0.5f)*0.5f + f(3)), sinf(t*f(0.5f)*0.5f + f(3))) * f(50); } else { diff --git a/samples/spaceshooter.cpp b/samples/spaceshooter.cpp index a4162317c..632dcd11a 100644 --- a/samples/spaceshooter.cpp +++ b/samples/spaceshooter.cpp @@ -264,7 +264,7 @@ struct LineParticleBarn struct Game { - CF_Rnd rnd; + CF_RndState rnd; PlayerShip player; AsteroidBarn asteroids; TrailBarn trails; @@ -287,8 +287,8 @@ struct Game Game* g; -float rnd_range(float lo, float hi) { return rnd_next_range(g->rnd, lo, hi); } -v2 rnd_range(v2 lo, v2 hi) { return V2(rnd_next_range(g->rnd, lo.x, hi.x), rnd_next_range(g->rnd, lo.y, hi.y)); } +float rnd_range(float lo, float hi) { return rnd_range(g->rnd, lo, hi); } +v2 rnd_range(v2 lo, v2 hi) { return V2(rnd_range(g->rnd, lo.x, hi.x), rnd_range(g->rnd, lo.y, hi.y)); } void TrailBarn::add(CF_Aabb box, float duration) { diff --git a/src/cute_draw.cpp b/src/cute_draw.cpp index 127a4d12c..02e75dea4 100644 --- a/src/cute_draw.cpp +++ b/src/cute_draw.cpp @@ -1688,8 +1688,8 @@ static bool s_text_fx_shake(TextEffect* effect) int seed = (int)(effect->elapsed * freq); float x = (float)effect->get_number("x", 2); float y = (float)effect->get_number("y", 2); - CF_Rnd rnd = cf_rnd_seed(seed); - v2 offset = V2(rnd_next_range(rnd, -x, y), rnd_next_range(rnd, -x, y)); + CF_RndState rnd = rnd_seed(seed); + v2 offset = V2(rnd_range(rnd, -x, y), rnd_range(rnd, -x, y)); effect->q0 += offset; effect->q1 += offset; return true;