Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

vtkExtensionsRNG.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 * 00003 * $Id: vtkExtensionsRNG.h,v 1.3 2004/08/10 07:37:21 xpxqx Exp $ 00004 * 00005 * Copyright (c) 2004 Sean McInerney 00006 * All rights reserved. 00007 * 00008 * See Copyright.txt or http://vtkextensions.sourceforge.net/Copyright.html 00009 * for details. 00010 * 00011 * This software is distributed WITHOUT ANY WARRANTY; without even 00012 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 * PURPOSE. See the above copyright notice for more information. 00014 * 00015 */ 00016 #ifndef VTK_EXTENSIONS_RNG_H_ 00017 # define VTK_EXTENSIONS_RNG_H_ 00018 # include "vtkExtensionsCommonConfigure.h" // vtkExtensions configuration 00019 # include "vtkExtensionsTypes.h" // vtkExtensions types 00020 // VTK Common 00021 # include "vtkCriticalSection.h" // member 00022 # include "vtkObject.h" 00023 00024 VTK_EXTENSIONS_NAMESPACE_BEGIN 00025 00034 class VTK_EXTENSIONS_COMMON_EXPORT vtkExtensionsRNG : public vtkObject 00035 { 00036 public: 00037 static vtkExtensionsRNG* New (void); 00038 vtkTypeRevisionMacro (vtkExtensionsRNG, vtkObject); 00039 void PrintSelf (ostream&, vtkIndent); 00040 00042 void GetRandomBytes (void* aBuffer, int aByteCount); 00043 00044 protected: 00045 vtkExtensionsRNG (void); 00046 ~vtkExtensionsRNG(); 00047 00048 //BTX 00049 // Syncronization primatives. 00050 vtkSimpleCriticalSection CriticalSection; 00051 // RNG. 00052 vtkUint32Type Q[1024]; // seeds 00053 vtkUint32Type C; 00054 vtkUint32Type I; 00055 00060 void CMWC (vtkUint32Type& aResult); 00061 //ETX 00062 00063 private: 00069 vtkExtensionsRNG (const vtkExtensionsRNG&); 00070 void operator= (const vtkExtensionsRNG&); 00072 }; 00073 00074 inline void 00075 vtkExtensionsRNG::CMWC (vtkUint32Type& aResult) 00076 { 00077 unsigned long long t, a = 123471786LL; 00078 vtkUint32Type x, r = VTK_EXTENSIONS_UINT32(0xFFFFFFFE); 00079 00080 this->I = (this->I + 1) & 1023; 00081 t = a * this->Q[this->I] + this->C; 00082 this->C = (t>>32); 00083 x = t + this->C; 00084 if (x < this->C) { x++; this->C++; } 00085 00086 aResult = (this->Q[this->I] = r - x); 00087 } 00088 00089 VTK_EXTENSIONS_NAMESPACE_END 00090 00091 #endif /* VTK_EXTENSIONS_RNG_H_ */ 00092 /* 00093 * End of: $Id: vtkExtensionsRNG.h,v 1.3 2004/08/10 07:37:21 xpxqx Exp $. 00094 * 00095 */

Generated on Tue Aug 10 03:37:39 2004 for vtkExtensions by doxygen 1.3.7