home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / djgpp / include / _randomi.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-20  |  2.1 KB  |  86 lines

  1. /* This is file _randomi.h */
  2. /* This file may have been modified by DJ Delorie (Jan 1991).  If so,
  3. ** these modifications are Coyright (C) 1991 DJ Delorie, 24 Kirsten Ave,
  4. ** Rochester NH, 03867-2954, USA.
  5. */
  6.  
  7. // This may look like C code, but it is really -*- C++ -*-
  8. /* 
  9. Copyright (C) 1988 Free Software Foundation
  10.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  11.  
  12. This file is part of GNU CC.
  13.  
  14. GNU CC is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY.  No author or distributor
  16. accepts responsibility to anyone for the consequences of using it
  17. or for whether it serves any particular purpose or works at all,
  18. unless he says so in writing.  Refer to the GNU CC General Public
  19. License for full details.
  20.  
  21. Everyone is granted permission to copy, modify and redistribute
  22. GNU CC, but only under the conditions described in the
  23. GNU CC General Public License.   A copy of this license is
  24. supposed to have been given to you along with GNU CC so you
  25. can know your rights and responsibilities.  It should be in a
  26. file named COPYING.  Among other things, the copyright notice
  27. and this notice must be preserved on all copies.  
  28. */
  29. #ifndef _RandomInterval_h
  30. #pragma once
  31. #define _RandomInterval_h 1
  32.  
  33. #include <_Random.h>
  34.  
  35. //
  36. //    The interval [lo..hi]
  37. // 
  38.  
  39. class RandomInterval: public Random {
  40. protected:
  41.     double pLow;
  42.     double pHigh;
  43. public:
  44.     RandomInterval(double low, double high, RNG *gen);
  45.  
  46.     double low();
  47.     double low(double x);
  48.     double high();
  49.     double high(double x);
  50.  
  51.     virtual double operator()();
  52. };
  53.  
  54.  
  55. //#ifdef __OPTIMIZE__
  56.  
  57. inline RandomInterval::RandomInterval(double low, double high, RNG *gen)
  58.  : (gen)
  59. {
  60.   if (low < high)
  61.   {
  62.     pLow = low; pHigh = high;
  63.   }
  64.   else
  65.   {
  66.     pLow = high; pHigh = low;
  67.   }
  68. }
  69.  
  70. inline double RandomInterval::low() { return pLow; }
  71.  
  72. inline double RandomInterval::low(double x) {
  73.   double tmp = pLow;
  74.   pLow = x; return tmp;
  75. }
  76.  
  77. inline double RandomInterval::high() { return pHigh; }
  78.  
  79. inline double RandomInterval::high(double x) {
  80.   double tmp = pHigh;
  81.   pHigh = x; return tmp;
  82. }
  83.  
  84. //#endif
  85. #endif
  86.