diff options
author | McCabe Maxsted | 2011-07-20 17:52:25 -0700 |
---|---|---|
committer | McCabe Maxsted | 2011-09-08 16:10:56 -0700 |
commit | 2a4afedf90d055cca16bb0ec53542ac67d2ae2c6 (patch) | |
tree | 14a88f35d396251443575e625495af4d852627a2 /linden/indra/llcommon | |
parent | Committing a useful .bat file for windows (diff) | |
download | meta-impy-2a4afedf90d055cca16bb0ec53542ac67d2ae2c6.zip meta-impy-2a4afedf90d055cca16bb0ec53542ac67d2ae2c6.tar.gz meta-impy-2a4afedf90d055cca16bb0ec53542ac67d2ae2c6.tar.bz2 meta-impy-2a4afedf90d055cca16bb0ec53542ac67d2ae2c6.tar.xz |
Added ll_frand(min, max) function
Diffstat (limited to 'linden/indra/llcommon')
-rw-r--r-- | linden/indra/llcommon/llrand.cpp | 15 | ||||
-rw-r--r-- | linden/indra/llcommon/llrand.h | 5 |
2 files changed, 20 insertions, 0 deletions
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) | |||
156 | return rv; | 156 | return rv; |
157 | } | 157 | } |
158 | 158 | ||
159 | F32 ll_frand(F32 min, F32 max) | ||
160 | { | ||
161 | llassert(min <= max); | ||
162 | F32 rv = min + ((max - min) * ll_internal_random_float()); | ||
163 | if (rv > 0) | ||
164 | { | ||
165 | if (rv >= max) return 0.0f; | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | if (rv <= min) return 0.0f; | ||
170 | } | ||
171 | return rv; | ||
172 | } | ||
173 | |||
159 | F64 ll_drand() | 174 | F64 ll_drand() |
160 | { | 175 | { |
161 | return ll_internal_random_double(); | 176 | 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(); | |||
83 | LL_COMMON_API F32 ll_frand(F32 val); | 83 | LL_COMMON_API F32 ll_frand(F32 val); |
84 | 84 | ||
85 | /** | 85 | /** |
86 | *@brief Generate a float from [min, max]. | ||
87 | */ | ||
88 | LL_COMMON_API F32 ll_frand(F32 min, F32 max); | ||
89 | |||
90 | /** | ||
86 | *@brief Generate a double from [0, 1.0). | 91 | *@brief Generate a double from [0, 1.0). |
87 | */ | 92 | */ |
88 | LL_COMMON_API F64 ll_drand(); | 93 | LL_COMMON_API F64 ll_drand(); |