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  }
35 
36  void setSeed(uint seed);
37  void setSeed(const uint key[], uint klength);
38 
39  void save(std::ostream &os, bool binary) const;
40  // Returns true if successful and false otherwise.
41  bool load(UT_IStream &is);
42 
43  // Unsigned integer random number generation
45  {
46  uint y;
47  if (myIndex == 624)
48  {
49  y = doReload();
50  myIndex = 1;
51  }
52  else
53  {
54  y = myState[myIndex++];
55  }
56 
57  y ^= (y >> 11);
58  y ^= (y << 7) & 0x9d2c5680U;
59  y ^= (y << 15) & 0xefc60000U;
60  return (y ^ (y >> 18));
61  }
62 
63  // Floating point generation: range := [0, 1)
65  {
66  SYS_FPRealUnionF tmp;
67  tmp.uval = 0x3f800000 | (0x007fffff & urandom());
68  return tmp.fval - CONST_FPREAL32(1.0);
69  }
70  // Floating point generation: range := [-.5, .5)
72  {
73  SYS_FPRealUnionF tmp;
74  tmp.uval = 0x3f800000 | (0x007fffff & urandom());
75  return tmp.fval - CONST_FPREAL32(1.5);
76  }
77 private:
78  uint doReload();
79 
80  uint myIndex;
81  uint myState[625];
82 };
83 
84 #endif
85 
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
#define UT_API
Definition: UT_API.h:13
GLint y
Definition: glcorearb.h:102
fpreal32 frandom()
Definition: UT_MTwister.h:64
UT_MersenneTwister(uint seed=5489U)
Definition: UT_MTwister.h:30
unsigned int uint
Definition: SYS_Types.h:40
fpreal32 frandom0()
Definition: UT_MTwister.h:71
#define CONST_FPREAL32(c)
Definition: SYS_Types.h:318
float fpreal32
Definition: SYS_Types.h:191