Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / Ice / IceRandom.h
1 /*
2  *      ICE / OPCODE - Optimized Collision Detection
3  * http://www.codercorner.com/Opcode.htm
4  * 
5  * Copyright (c) 2001-2008 Pierre Terdiman,  pierre@codercorner.com
6
7 This software is provided 'as-is', without any express or implied warranty.
8 In no event will the authors be held liable for any damages arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose, 
10 including commercial applications, and to alter it and redistribute it freely, 
11 subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
14 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
15 3. This notice may not be removed or altered from any source distribution.
16 */
17 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 /**
19  *      Contains code for random generators.
20  *      \file           IceRandom.h
21  *      \author         Pierre Terdiman
22  *      \date           August, 9, 2001
23  */
24 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25
26 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 // Include Guard
28 #ifndef __ICERANDOM_H__
29 #define __ICERANDOM_H__
30
31         FUNCTION ICECORE_API    void    SRand(udword seed);
32         FUNCTION ICECORE_API    udword  Rand();
33
34         //! Returns a unit random floating-point value
35         inline_ float UnitRandomFloat() { return float(Rand()) * ONE_OVER_RAND_MAX;     }
36
37         //! Returns a random index so that 0<= index < max_index
38         ICECORE_API     udword GetRandomIndex(udword max_index);
39
40         class ICECORE_API BasicRandom
41         {
42                 public:
43
44                 //! Constructor
45                 inline_                         BasicRandom(udword seed=0)      : mRnd(seed)    {}
46                 //! Destructor
47                 inline_                         ~BasicRandom()                                                          {}
48
49                 inline_ void            SetSeed(udword seed)            { mRnd = seed;                                                                                  }
50                 inline_ udword          GetCurrentValue()       const   { return mRnd;                                                                                  }
51                 inline_ udword          Randomize()                                     { mRnd = mRnd * 2147001325 + 715136305; return mRnd;    }
52
53                 private:
54                                 udword          mRnd;
55         };
56
57 #endif // __ICERANDOM_H__
58