X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Fpublic-api%2Fmath%2Frandom.h;h=2d5d2372aa8dcb2e38ec5c066066f3d0f4714ca9;hb=649ec06daecb510fb84fe4642a6af957f127e7ab;hp=9b9e97e0bc10920ba771a5c6ba93e343e8ea3384;hpb=29b1efeeb79f84be5eefb3e3067ec9b237f0f262;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/public-api/math/random.h b/dali/public-api/math/random.h index 9b9e97e..2d5d237 100644 --- a/dali/public-api/math/random.h +++ b/dali/public-api/math/random.h @@ -2,7 +2,7 @@ #define __DALI_RANDOM_H__ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,14 @@ namespace Dali { +/** + * @addtogroup dali_core_math + * @{ + */ /** * @brief Provides methods to generate and use random values. + * @SINCE_1_0.0 */ namespace Random { @@ -34,21 +39,35 @@ namespace Random * @brief Returns a random number between f0 and f1. * * Note, uses a limited number of values. - * @param[in] f0 the lower bound - * @param[in] f1 the upper bound - * @return a random value between the lower and upper bound + * @SINCE_1_0.0 + * @param[in] f0 The lower bound + * @param[in] f1 The upper bound + * @return A random value between the lower and upper bound */ inline float Range(float f0, float f1) { float min = std::min(f0, f1); float max = std::max(f0, f1); - return min + (rand() & 0xfff) * (max-min) * (1.0f/4095.0f); + + // Ensure we initialize only once. As it's inlined, this static variable will exist in the code-block using it, thus, + // will be created and then initialized again when another code-block uses this. + static bool initialized( false ); + if( !initialized ) + { + auto seed = time( NULL ); + srand( seed ); + initialized = true; + } + + auto randValue = rand(); + return (randValue & 0xfff) * (1.0f/4095.0f) * (max-min) + min; } /** * @brief Function to return a normalized axis in a random direction. * - * @return the axis + * @SINCE_1_0.0 + * @return The axis */ inline Vector4 Axis() { @@ -68,6 +87,9 @@ inline Vector4 Axis() } // namespace Random +/** + * @} + */ } // namespace Dali #endif // __DALI_RANDOM_H__