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 | } |