X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Fpublic-api%2Fmath%2Frandom.h;h=bc6fcbd68100f28ca8bc800919f1dfe4046b9f30;hb=refs%2Ftags%2Fsubmit%2Ftizen%2F20180716.055223;hp=97818f587e1cf0c64b5f0839dd3f004937a51f46;hpb=4c1d314e5532f093daa46fcf038f47cde2c70a1b;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/public-api/math/random.h b/dali/public-api/math/random.h old mode 100644 new mode 100755 index 97818f5..bc6fcbd --- 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. @@ -17,6 +17,8 @@ * limitations under the License. * */ +// EXTERNAL INCLUDES +#include // INTERNAL INCLUDES #include @@ -48,8 +50,19 @@ inline float Range(float f0, float f1) { float min = std::min(f0, f1); float max = std::max(f0, f1); - srand( time( NULL ) ); - 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; } /**