00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
#ifndef VTK_EXTENSIONS_RNG_H_
00017
# define VTK_EXTENSIONS_RNG_H_
00018
# include "vtkExtensionsCommonConfigure.h"
00019
# include "vtkExtensionsTypes.h"
00020
00021
# include "vtkCriticalSection.h"
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
00049
00050 vtkSimpleCriticalSection CriticalSection;
00051
00052 vtkUint32Type Q[1024];
00053 vtkUint32Type C;
00054 vtkUint32Type I;
00055
00060
void CMWC (vtkUint32Type& aResult);
00061
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
00092
00093
00094
00095