home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / LIBMAT.ZIP / MATRAND.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-16  |  2.3 KB  |  82 lines

  1. /**************************************************/
  2. /*    matrand.hpp header for matRandom class      */
  3. /**************************************************/
  4.  
  5.  
  6. /**************************************************/
  7. /*            MatClass Source File                */
  8. /*       Copyright of C. R. Birchenhall           */
  9. /*       University of Manchester, UK.            */
  10. /*   MatClass is freeware. This file should be    */
  11. /* made freely available to users of any software */
  12. /* whose creation is wholly or partly dependent   */
  13. /*                on this file.                   */
  14. /**************************************************/
  15.  
  16. #ifndef MATRIX_H
  17. #include "matrix.hpp"
  18. #endif
  19.  
  20. #ifndef MATRAND_H
  21.  
  22. #define MATRAND_H
  23.  
  24.  
  25. // random generators
  26.  
  27.       enum distribution
  28.       {
  29.           UNIFORM, NORMAL, EXPON, GAMMA, POISSON, BINOMIAL
  30.       } ; // distribution
  31.  
  32. class matRandom : public matObject
  33. {
  34.  
  35.       int x, y, z, normalOk ;
  36.       REAL normal0 ;
  37.  
  38.       matrix& operator()( matrix& x, distribution dist ,
  39.               REAL p1 , REAL p2 ) ;
  40.  
  41.    public :
  42.  
  43.       matRandom( int newX = 26, int newY = 2, int newZ = 1947 ) ;
  44.       matRandom( matRandom& ran ) ;
  45.       void operator = ( matRandom& ran ) ;
  46.       ~matRandom( void ) ;
  47.  
  48.       outFile& put( outFile& f  ) M_CONST ;
  49.       inFile& get( inFile& f ) ;
  50.       outFile& info( outFile& f ) M_CONST ;
  51.  
  52.  
  53.       void seed( int newX, int newY, int newZ ) ;
  54.       REAL uniform( void ) ;
  55.       REAL normal( REAL mean = 0.0, REAL std = 1.0 ) ;
  56.       REAL expon( REAL mean = 1.0 ) ;
  57.       REAL gamma( REAL a = 1.0 ) ;
  58.       REAL poisson( REAL mean = 1.0 ) ;
  59.       REAL binomial( int n, REAL p ) ;
  60.  
  61.       matrix& uniform( matrix& x )
  62.           { return (*this)( x, UNIFORM, 0, 0 ) ; }
  63.       matrix& normal( matrix& x, REAL mean = 0.0, REAL std = 1.0 )
  64.           { return (*this)( x, NORMAL, mean, std ) ; }
  65.       matrix& expon( matrix& x, REAL mean = 1.0 )
  66.           { return (*this)( x, EXPON, mean, 0 ) ; }
  67.       matrix& gamma( matrix& x, REAL a = 1.0 )
  68.           { return (*this)( x, GAMMA, a, 0 ) ; }
  69.       matrix& poisson( matrix& x, REAL mean = 1.0 )
  70.           { return (*this)( x, POISSON, mean, 0 ) ; }
  71.       matrix& binomial( matrix& x, int n, REAL p )
  72.           { return (*this)( x, BINOMIAL, REAL(n), p )  ; }
  73.  
  74.  
  75. } ; // matRandom
  76.  
  77.  
  78. #endif
  79.  
  80.  
  81.  
  82.