1 /*
2  *  $Id$
3  *
4  * SocketAPI implementation for the sctplib.
5  * Copyright (C) 1999-2020 by Thomas Dreibholz
6  *
7  * Realized in co-operation between
8  * - Siemens AG
9  * - University of Essen, Institute of Computer Networking Technology
10  * - University of Applied Sciences, Muenster
11  *
12  * Acknowledgement
13  * This work was partially funded by the Bundesministerium fuer Bildung und
14  * Forschung (BMBF) of the Federal Republic of Germany (Foerderkennzeichen 01AK045).
15  * The authors alone are responsible for the contents.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21 
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  *
30  * Contact: discussion@sctp.de
31  *          dreibh@iem.uni-due.de
32  *          tuexen@fh-muenster.de
33  *
34  * Purpose: Randomizer Implementation
35  *
36  */
37 
38 
39 #ifndef RANDOM_H
40 #define RANDOM_H
41 
42 
43 #include "tdsystem.h"
44 
45 
46 
47 /**
48   * This class is an randomizer. The randomizer algorithm will calculate
49   * random numbers with seed given by system timer (microseconds since
50   * January 01, 1970) or given by a number.
51   *
52   * @short   Randomizer
53   * @author  Thomas Dreibholz (dreibh@iem.uni-due.de)
54   * @version 1.0
55   */
56 class Randomizer
57 {
58    // ====== Constructor ====================================================
59    public:
60    /**
61      * Constructor. Seed will be initialized by system timer (microseconds
62      * since January 01, 1970).
63      */
64    Randomizer();
65 
66    // ====== Random functions ===============================================
67    /**
68      * Set seed by system timer (microseconds since January 01, 1970).
69      */
70    void setSeed();
71 
72    /**
73      * Set seed by given number.
74      *
75      * @param seed Seed value.
76      */
77    void setSeed(const cardinal seed);
78 
79    /**
80      * Get 8-bit random number.
81      *
82      * @return The generated number.
83      */
84    inline card8 random8();
85 
86    /**
87      * Get 16-bit random number.
88      *
89      * @return The generated number.
90      */
91    inline card16 random16();
92 
93    /**
94      * Get 32-bit random number.
95      *
96      * @return The generated number.
97      */
98    inline card32 random32();
99 
100    /**
101      * Get 64-bit random number.
102      *
103      * @return The generated number.
104      */
105    inline card64 random64();
106 
107    /**
108      * Get double random number out of interval [0,1].
109      *
110      * @return The generated number.
111      */
112    inline double random();
113 
114    /**
115      * Get double random cardinal number out of interval [a,b].
116      *
117      * @return The generated number.
118      */
119    cardinal random(const cardinal a, const cardinal b);
120 
121    /**
122      * Get double random double number out of interval [a,b].
123      *
124      * @return The generated number.
125      */
126    double random(const double a, const double b);
127 
128 
129    // ====== Private data ===================================================
130    private:
131    card32 Value;
132 };
133 
134 
135 #include "randomizer.icc"
136 
137 
138 #endif
139