Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
floatrand.h
00001 /* 00002 Copyright (C) 2004 by Jorrit Tyberghein 00003 Copyright (C) 2005 by Eric Sunshine 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSUTIL_FLOATRAND_H__ 00021 #define __CS_CSUTIL_FLOATRAND_H__ 00022 00023 #include "csextern.h" 00024 00028 class CS_CSUTIL_EXPORT csRandomFloatGen 00029 { 00030 private: 00031 unsigned int seed; 00032 00033 public: 00035 csRandomFloatGen () 00036 { Initialize(); } 00038 csRandomFloatGen (unsigned int seed) 00039 { Initialize(seed); } 00040 00042 void Initialize(); 00044 void Initialize(unsigned int new_seed) 00045 { seed = new_seed; } 00046 00048 float Get() 00049 { 00050 unsigned int const b = 1664525; 00051 unsigned int const c = 1013904223; 00052 seed = b * seed + c; 00053 uint32 temp = 0x3f800000 | (0x007fffff & seed); 00054 return (*(float*)&temp) - 1.0; 00055 } 00056 00058 float Get(float max) 00059 { 00060 return max * Get(); 00061 } 00062 00064 float Get(float min, float max) 00065 { 00066 float const w = max - min; 00067 return min + w * Get(); 00068 } 00069 00071 float GetAngle() 00072 { 00073 return TWO_PI * Get(); 00074 } 00075 }; 00076 00077 #endif // __CS_CSUTIL_FLOATRAND_H__
Generated for Crystal Space by doxygen 1.3.9.1