home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / mlcg.h < prev    next >
C/C++ Source or Header  |  1993-07-23  |  2KB  |  100 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 GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23. #ifndef _MLCG_h
  24. #pragma once
  25. #define _MLCG_h 1 
  26.  
  27. #include "RNG.h"
  28. #include <math.h>
  29.  
  30. //
  31. //    Multiplicative Linear Conguential Generator
  32. //
  33.  
  34. class MLCG : public RNG {
  35.     long initialSeedOne;
  36.     long initialSeedTwo;
  37.     long seedOne;
  38.     long seedTwo;
  39.  
  40. protected:
  41.  
  42. public:
  43.     MLCG(long seed1 = 0, long seed2 = 1);
  44.     //
  45.     // Return a long-words word of random bits
  46.     //
  47.     virtual unsigned long asLong();
  48.     virtual void reset();
  49.     long seed1();
  50.     void seed1(long);
  51.     long seed2();
  52.     void seed2(long);
  53.     void reseed(long, long);
  54. };
  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. inline
  91. MLCG::MLCG(long s1 = 0, long s2 = 1)
  92. {
  93.     initialSeedOne = s1;
  94.     initialSeedTwo = s2;
  95.     reset();
  96. }
  97.  
  98. #endif
  99.  
  100.