From 84987bfdf2013f19a59f44fe4803f539dbcac95e Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Sat, 22 Dec 2012 16:19:47 -0800 Subject: [PATCH] Added helper float random functions frnd 0.0 to 1.0f and frndh -1.0f to 1.0f. --- include/bx/rng.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/bx/rng.h b/include/bx/rng.h index 23f54f3..ece8bd8 100644 --- a/include/bx/rng.h +++ b/include/bx/rng.h @@ -92,6 +92,21 @@ namespace bx uint32_t m_jsr; }; + /// Returns random number between 0.0f and 1.0f. + template + inline float frnd(Ty* _rng) + { + uint32_t rnd = _rng->gen() & UINT16_MAX; + return float(rnd) * 1.0f/float(UINT16_MAX); + } + + /// Returns random number between -1.0f and 1.0f. + template + inline float frndh(Ty* _rng) + { + return 2.0f * bx::frnd(_rng) - 1.0f; + } + } // namespace bx #endif // __BX_RNG_H__