xref: /386bsd/usr/src/lib/libg++/g++-include/ACG.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 _ACG_h
24 #define _ACG_h 1
25 
26 #include <RNG.h>
27 #include <math.h>
28 #ifdef __GNUG__
29 #pragma once
30 #pragma interface
31 #endif
32 
33 //
34 //	Additive number generator. This method is presented in Volume II
35 //	of The Art of Computer Programming by Knuth. I've coded the algorithm
36 //	and have added the extensions by Andres Nowatzyk of CMU to randomize
37 //	the result of algorithm M a bit	by using an LCG & a spatial
38 //	permutation table.
39 //
40 //	The version presented uses the same constants for the LCG that Andres
41 //	uses (chosen by trial & error). The spatial permutation table is
42 //	the same size (it's based on word size). This is for 32-bit words.
43 //
44 //	The ``auxillary table'' used by the LCG table varies in size, and
45 //	is chosen to be the the smallest power of two which is larger than
46 //	twice the size of the state table.
47 //
48 
49 class ACG : public RNG {
50 
51     unsigned long initialSeed;	// used to reset generator
52     int initialTableEntry;
53 
54     unsigned long *state;
55     unsigned long *auxState;
56     short stateSize;
57     short auxSize;
58     unsigned long lcgRecurr;
59     short j;
60     short k;
61 
62 protected:
63 
64 public:
65     ACG(unsigned long seed = 0, int size = 55);
66     virtual ~ACG();
67     //
68     // Return a long-words word of random bits
69     //
70     virtual unsigned long asLong();
71     virtual void reset();
72 };
73 
74 #endif
75