From 2a4afedf90d055cca16bb0ec53542ac67d2ae2c6 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 20 Jul 2011 17:52:25 -0700 Subject: Added ll_frand(min, max) function --- linden/indra/llcommon/llrand.cpp | 15 +++++++++++++++ linden/indra/llcommon/llrand.h | 5 +++++ 2 files changed, 20 insertions(+) (limited to 'linden/indra/llcommon') diff --git a/linden/indra/llcommon/llrand.cpp b/linden/indra/llcommon/llrand.cpp index 0b2f8b8..fb2bcd3 100644 --- a/linden/indra/llcommon/llrand.cpp +++ b/linden/indra/llcommon/llrand.cpp @@ -156,6 +156,21 @@ F32 ll_frand(F32 val) return rv; } +F32 ll_frand(F32 min, F32 max) +{ + llassert(min <= max); + F32 rv = min + ((max - min) * ll_internal_random_float()); + if (rv > 0) + { + if (rv >= max) return 0.0f; + } + else + { + if (rv <= min) return 0.0f; + } + return rv; +} + F64 ll_drand() { return ll_internal_random_double(); diff --git a/linden/indra/llcommon/llrand.h b/linden/indra/llcommon/llrand.h index 73ea179..0b68a17 100644 --- a/linden/indra/llcommon/llrand.h +++ b/linden/indra/llcommon/llrand.h @@ -83,6 +83,11 @@ LL_COMMON_API F32 ll_frand(); LL_COMMON_API F32 ll_frand(F32 val); /** + *@brief Generate a float from [min, max]. + */ +LL_COMMON_API F32 ll_frand(F32 min, F32 max); + +/** *@brief Generate a double from [0, 1.0). */ LL_COMMON_API F64 ll_drand(); -- cgit v1.1