1 #ifndef __DALI_RANDOM_H__
2 #define __DALI_RANDOM_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/math/vector4.h>
28 * @brief Provides methods to generate and use random values.
34 * @brief Returns a random number between f0 and f1.
36 * Note, uses a limited number of values.
37 * @param[in] f0 the lower bound
38 * @param[in] f1 the upper bound
39 * @return a random value between the lower and upper bound
41 inline float Range(float f0, float f1)
43 float min = std::min(f0, f1);
44 float max = std::max(f0, f1);
45 return min + (rand() & 0xfff) * (max-min) * (1.0f/4095.0f);
49 * @brief Function to return a normalized axis in a random direction.
56 // This function needs to return a vector with direction, that is to say a non-zero vector
57 // There is a possibility that a random vector will be a zero vector, so a loop is needed to ensure that a non-zero vector is returned
60 axis.x = Range(-1.0f, 1.0f);
61 axis.y = Range( 0.0f, 1.0f);
62 axis.z = Range( 0.0f, 1.0f);
64 } while (axis == Vector4::ZERO);
73 #endif // __DALI_RANDOM_H__