HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_Random.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #ifndef __SIM_Random_h__
9 #define __SIM_Random_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_DataUtils.h"
13 
14 /// This class defines a bunch of useful tools for random number
15 /// generation. It is designed to be attached as subdata to objects
16 /// or solvers that need a stream of random numbers.
17 class SIM_API SIM_Random : public SIM_Data
18 {
19 public:
20  // Methods to manipulate the stream:
21 
22  /// Sets the seed to the system.
23  void setSeed(uint seed);
24 
25  /// Gets a random unsigned integer
26  uint urandom();
27 
28  /// Returns a random float from [0..1)
29  fpreal frandom();
30 
31  /// Returns a random float from [-.5...5)
32  fpreal frandom0();
33 
34  /// Returns a random integer from [0..choices-1]
35  /// 0 choices will return 0. Negative choices will go
36  /// for [-choices+1..0]
37  int choice(int choices);
38 
39  /// Returns a number within the range [a..b]
40  /// In the floating point case, the range is [a..b)
41  int irange(int a, int b);
42  fpreal frange(fpreal a, fpreal b);
43 
44  /// Returns true with the givent probability. < 0 always false,
45  /// > 1 always true.
46  bool chance(fpreal probability);
47 
48 protected:
49  explicit SIM_Random(const SIM_DataFactory *factory);
50  virtual ~SIM_Random();
51 
52  /// Override this function to initialize the random number generator.
53  virtual void setSeedSubclass(uint seed) = 0;
54  /// Override this function to implement a new random number generator.
55  virtual uint urandomSubclass() = 0;
56 
57 private:
60 };
61 
62 #endif
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
#define DECLARE_CLASSNAME(DataClass, SuperClass)
Definition: SIM_DataUtils.h:20
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
unsigned int uint
Definition: SYS_Types.h:40
double fpreal
Definition: SYS_Types.h:270
#define SIM_API
Definition: SIM_API.h:10