#include <Random.h>
Public Member Functions | |
| Random (void) | |
| Random (unsigned long seed) | |
| void | init (unsigned long seed) |
| void | skip (void) |
| void | split (int iStream, int numStreams) |
| BigReal | uniform (void) |
| BigReal | gaussian (void) |
| Vector | gaussian_vector (void) |
| long | integer (void) |
| template<class Elem> | |
| void | reorder (Elem *a, int n) |
|
|
Definition at line 50 of file Random.h. 00050 {
00051 init(0);
00052 rand48_seed = RAND48_SEED;
00053 }
|
|
|
Definition at line 56 of file Random.h. 00056 {
00057 init(seed);
00058 }
|
|
|
Definition at line 116 of file Random.h. References BigReal. Referenced by Controller::langevinPiston1(), and Controller::langevinPiston2(). 00116 {
00117 BigReal fac, r, v1, v2;
00118
00119 if (second_gaussian_waiting) {
00120 second_gaussian_waiting = 0;
00121 return second_gaussian;
00122 } else {
00123 r = 2.; // r >= 1.523e-8 ensures abs result < 6
00124 while (r >=1. || r < 1.523e-8) { // make sure we are within unit circle
00125 v1 = 2.0 * uniform() - 1.0;
00126 v2 = 2.0 * uniform() - 1.0;
00127 r = v1*v1 + v2*v2;
00128 }
00129 fac = sqrt(-2.0 * log(r)/r);
00130 // now make the Box-Muller transformation to get two normally
00131 // distributed random numbers. Save one and return the other.
00132 second_gaussian_waiting = 1;
00133 second_gaussian = v1 * fac;
00134 return v2 * fac;
00135 }
00136 }
|
|
|
Definition at line 139 of file Random.h. Referenced by Controller::langevinPiston1(), Controller::langevinPiston2(), Sequencer::langevinVelocities(), Sequencer::langevinVelocitiesBBK2(), Sequencer::reassignVelocities(), and Sequencer::reinitVelocities().
|
|
|
Definition at line 61 of file Random.h. References INT64_LITERAL, and RAND48_SEED. 00061 {
00062 second_gaussian = 0;
00063 second_gaussian_waiting = 0;
00064 rand48_seed = seed & INT64_LITERAL(0x00000000ffffffff);
00065 rand48_seed = rand48_seed << 16;
00066 rand48_seed |= RAND48_SEED & INT64_LITERAL(0x0000ffff);
00067 rand48_mult = RAND48_MULT;
00068 rand48_add = RAND48_ADD;
00069 }
|
|
|
Definition at line 144 of file Random.h. References INT64_LITERAL. 00144 {
00145 skip();
00146 return ( ( rand48_seed >> 17 ) & INT64_LITERAL(0x000000007fffffff) );
00147 }
|
|
||||||||||||||||
|
Definition at line 150 of file Random.h. Referenced by ComputePmeMgr::initialize(), and PmePencil< CBase_PmeZPencil >::order_init(). 00150 {
00151 for ( int i = 0; i < (n-1); ++i ) {
00152 int ie = i + ( integer() % (n-i) );
00153 if ( ie == i ) continue;
00154 const Elem e = a[ie];
00155 a[ie] = a[i];
00156 a[i] = e;
00157 }
00158 }
|
|
|
Definition at line 72 of file Random.h. 00072 {
00073 rand48_seed = ( rand48_seed * rand48_mult + rand48_add ) & RAND48_MASK;
00074 }
|
|
||||||||||||
|
Definition at line 77 of file Random.h. References int64. Referenced by Controller::Controller(), and Sequencer::Sequencer(). 00077 {
00078
00079 int i;
00080
00081 // make sure that numStreams is odd to ensure maximum period
00082 numStreams |= 1;
00083
00084 // iterate to get to the correct stream
00085 for ( i = 0; i < iStream; ++i ) skip();
00086
00087 // save seed and add so we can use skip() for our calculations
00088 int64 save_seed = rand48_seed;
00089
00090 // calculate c *= ( 1 + a + ... + a^(numStreams-1) )
00091 rand48_seed = rand48_add;
00092 for ( i = 1; i < numStreams; ++i ) skip();
00093 int64 new_add = rand48_seed;
00094
00095 // calculate a = a^numStreams
00096 rand48_seed = rand48_mult;
00097 rand48_add = 0;
00098 for ( i = 1; i < numStreams; ++i ) skip();
00099 rand48_mult = rand48_seed;
00100
00101 rand48_add = new_add;
00102 rand48_seed = save_seed;
00103
00104 second_gaussian = 0;
00105 second_gaussian_waiting = 0;
00106 }
|
|
|
Definition at line 109 of file Random.h. References BigReal, and INT64_LITERAL. 00109 {
00110 skip();
00111 const double exp48 = ( 1.0 / (double)(INT64_LITERAL(1) << 48) );
00112 return ( (double) rand48_seed * exp48 );
00113 }
|
1.3.9.1