Changeset 579

Show
Ignore:
Timestamp:
08/22/09 14:50:03 (15 years ago)
Author:
smidl
Message:

Implementation of mixtools randun function

Location:
library
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/itpp_ext.cpp

    r508 r579  
    376376        } 
    377377} 
    378 } 
     378 
     379class 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}; 
     389static RandunStorage randun_global_storage; 
     390double RandunStorage::seed=1111111; 
     391int RandunStorage::counter=0; 
     392double randun(){return randun_global_storage.get();}; 
     393vec randun(int n){vec res(n); for(int i=0;i<n;i++){res(i)=randun();}; return res;}; 
     394mat 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  
    103103//! implementation of matlab triu function 
    104104void 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) 
     109double randun(); 
     110//! implementation of Mixtools function randun 
     111vec randun(int n); 
     112//! implementation of Mixtools function randun 
     113mat randun(int n, int m); 
     114 
    105115} 
    106116