home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__inc / xmlcg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-23  |  1.9 KB  |  93 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef _MLCG_h
  19. #define _MLCG_h 1 
  20. #ifdef __GNUG__
  21. #pragma once
  22. #pragma interface
  23. #endif
  24.  
  25. #include <xrng.h>
  26. #include <math.h>
  27.  
  28. //
  29. //    Multiplicative Linear Conguential Generator
  30. //
  31.  
  32. class MLCG : public RNG {
  33.     long initialSeedOne;
  34.     long initialSeedTwo;
  35.     long seedOne;
  36.     long seedTwo;
  37.  
  38. protected:
  39.  
  40. public:
  41.     MLCG(long seed1 = 0, long seed2 = 1);
  42.     //
  43.     // Return a long-words word of random bits
  44.     //
  45.     virtual unsigned long asLong();
  46.     virtual void reset();
  47.     long seed1();
  48.     void seed1(long);
  49.     long seed2();
  50.     void seed2(long);
  51.     void reseed(long, long);
  52. };
  53.  
  54. #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
  55.  
  56. inline long
  57. MLCG::seed1()
  58. {
  59.     return(seedOne);
  60. }
  61.  
  62. inline void
  63. MLCG::seed1(long s)
  64. {
  65.     initialSeedOne = s;
  66.     reset();
  67. }
  68.  
  69. inline long
  70. MLCG::seed2()
  71. {
  72.     return(seedTwo);
  73. }
  74.  
  75. inline void
  76. MLCG::seed2(long s)
  77. {
  78.     initialSeedTwo = s;
  79.     reset();
  80. }
  81.  
  82. inline void
  83. MLCG::reseed(long s1, long s2)
  84. {
  85.     initialSeedOne = s1;
  86.     initialSeedTwo = s2;
  87.     reset();
  88. }
  89.  
  90. #endif
  91.  
  92. #endif
  93.