Changeset 579
- Timestamp:
- 08/22/09 14:50:03 (15 years ago)
- Location:
- library
- Files:
-
- 1 added
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/itpp_ext.cpp
r508 r579 376 376 } 377 377 } 378 } 378 379 class RandunStorage{ 380 const double A; 381 const double M; 382 static double seed; 383 static int counter; 384 public: 385 RandunStorage(): A(16807), M(2147483647) {}; 386 void set_seed(double seed0){seed=seed0;} 387 double get(){seed=mod(A*seed,M); counter++; return seed/M;} 388 }; 389 static RandunStorage randun_global_storage; 390 double RandunStorage::seed=1111111; 391 int RandunStorage::counter=0; 392 double randun(){return randun_global_storage.get();}; 393 vec randun(int n){vec res(n); for(int i=0;i<n;i++){res(i)=randun();}; return res;}; 394 mat randun(int n, int m){mat res(n,m); for(int i=0;i<n*m;i++){res(i)=randun();}; return res;}; 395 396 } -
library/bdm/itpp_ext.h
r508 r579 103 103 //! implementation of matlab triu function 104 104 void triu(mat &A); 105 106 //! implementation of Mixtools function randun 107 //! This function uses Park-Miller linear congruential pseudo-random generator with A=16807 B=0 M=2^31-1 108 //! (it spans all 2^31-1 numbers and has good statistical properties) 109 double randun(); 110 //! implementation of Mixtools function randun 111 vec randun(int n); 112 //! implementation of Mixtools function randun 113 mat randun(int n, int m); 114 105 115 } 106 116