HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_MTwister.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  * NAME: UT_MTwister.h ( UT Library, C++)
7  *
8  * COMMENTS: The Mersenne Twister
9  *
10  * The Mersenne Twister code is licensed under GNU and includes the following
11  * notice:
12  *
13  * Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
14  * All rights reserved.
15  *
16  */
17 
18 #ifndef __UT_Random__
19 #define __UT_Random__
20 
21 #include "UT_API.h"
22 #include <SYS/SYS_Types.h>
23 #include <SYS/SYS_Math.h>
24 #include <iosfwd>
25 
26 class UT_IStream;
27 
29 public:
31  {
32  setSeed(seed);
33  }
34 
35  void setSeed(uint seed);
36  void setSeed(const uint key[], uint klength);
37 
38  void save(std::ostream &os, bool binary) const;
39  // Returns true if successful and false otherwise.
40  bool load(UT_IStream &is);
41 
42  // Unsigned integer random number generation
44  {
45  uint y;
46  if (myIndex == 624)
47  {
48  y = doReload();
49  myIndex = 1;
50  }
51  else
52  {
53  y = myState[myIndex++];
54  }
55 
56  y ^= (y >> 11);
57  y ^= (y << 7) & 0x9d2c5680U;
58  y ^= (y << 15) & 0xefc60000U;
59  return (y ^ (y >> 18));
60  }
61 
62  // Floating point generation: range := [0, 1)
64  {
65  SYS_FPRealUnionF tmp;
66  tmp.uval = 0x3f800000 | (0x007fffff & urandom());
67  return tmp.fval - CONST_FPREAL32(1.0);
68  }
69  // Floating point generation: range := [-.5, .5)
71  {
72  SYS_FPRealUnionF tmp;
73  tmp.uval = 0x3f800000 | (0x007fffff & urandom());
74  return tmp.fval - CONST_FPREAL32(1.5);
75  }
76 private:
77  uint doReload();
78 
79  uint myIndex;
80  uint myState[625];
81 };
82 
83 #endif
84 
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
#define UT_API
Definition: UT_API.h:14
GLint y
Definition: glcorearb.h:103
fpreal32 frandom()
Definition: UT_MTwister.h:63
float fpreal32
Definition: SYS_Types.h:200
UT_MersenneTwister(uint seed=5489U)
Definition: UT_MTwister.h:30
fpreal32 frandom0()
Definition: UT_MTwister.h:70
#define CONST_FPREAL32(c)
Definition: SYS_Types.h:325
unsigned int uint
Definition: SYS_Types.h:45