xref: /386bsd/usr/include/nonstd/gnu/g++/MLCG.h (revision a2142627)
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 #define _MLCG_h 1
25 #ifdef __GNUG__
26 #pragma once
27 #pragma interface
28 #endif
29 
30 #include <RNG.h>
31 #include <math.h>
32 
33 //
34 //	Multiplicative Linear Conguential Generator
35 //
36 
37 class MLCG : public RNG {
38     long initialSeedOne;
39     long initialSeedTwo;
40     long seedOne;
41     long seedTwo;
42 
43 protected:
44 
45 public:
46     MLCG(long seed1 = 0, long seed2 = 1);
47     //
48     // Return a long-words word of random bits
49     //
50     virtual unsigned long asLong();
51     virtual void reset();
52     long seed1();
53     void seed1(long);
54     long seed2();
55     void seed2(long);
56     void reseed(long, long);
57 };
58 
59 #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
60 
61 inline long
seed1()62 MLCG::seed1()
63 {
64     return(seedOne);
65 }
66 
67 inline void
seed1(long s)68 MLCG::seed1(long s)
69 {
70     initialSeedOne = s;
71     reset();
72 }
73 
74 inline long
seed2()75 MLCG::seed2()
76 {
77     return(seedTwo);
78 }
79 
80 inline void
seed2(long s)81 MLCG::seed2(long s)
82 {
83     initialSeedTwo = s;
84     reset();
85 }
86 
87 inline void
reseed(long s1,long s2)88 MLCG::reseed(long s1, long s2)
89 {
90     initialSeedOne = s1;
91     initialSeedTwo = s2;
92     reset();
93 }
94 
95 #endif
96 
97 #endif
98