File: RandomSource.h

package info (click to toggle)
between 6%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch
  • size: 3,532 kB
  • sloc: cpp: 28,110; php: 718; ansic: 638; objc: 245; sh: 236; makefile: 99; perl: 67
file content (86 lines) | stat: -rw-r--r-- 2,060 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Jason Rohrer
// RandomSource.h

/**
*
*	abstract interface for random number generation
*
*		Can be implemented by:
*			--stdlib rand() function calls
*			--seed file full of random numbers
*
*	Created 12-7-99
*	Mods:
*   	Jason Rohrer	9-28-2000	Added a getRandomBoundedInt()
*									interface to faciliate retrieving
*									an integer in a given range [a,b]
*									where each integer in the range
*									has the same probability of being
*									returned.
*   	Jason Rohrer	12-16-2000	Added a getRandomDouble() interface.
*   	Jason Rohrer	11-21-2005	Added a virtual destructor.
*   	Jason Rohrer	07-09-2006	Added a getRandomBoundedDouble interface.
*   	Jason Rohrer	07-27-2006	Added a getRandomBoolean interface.
*/

#include "minorGems/common.h"



#ifndef RANDOM_SOURCE_INCLUDED
#define RANDOM_SOURCE_INCLUDED


class RandomSource {

	public:		
		// pure virtual functions implemented by inheriting classes		
		
		virtual float getRandomFloat() = 0;	// in interval [0,1.0]
		virtual double getRandomDouble() = 0; // in interval [0,1.0]
		virtual unsigned int getRandomInt() = 0;		// in interval [0,MAX]
		virtual unsigned int getIntMax() = 0;	// returns MAX
		
		/**
		 * Returns a random integer in [rangeStart,rangeEnd]
		 * where each integer in the range has an equal
		 * probability of occuring.
		 */
		virtual int getRandomBoundedInt( int inRangeStart,
			int inRangeEnd ) = 0;


        /**
		 * Returns a random double in [rangeStart,rangeEnd].
		 */
		virtual double getRandomBoundedDouble( double inRangeStart,
			double inRangeEnd ) = 0;


        
        /**
         * Gets a random true/false value.
         */
        virtual char getRandomBoolean() = 0;

        
        
        virtual ~RandomSource();

        
	protected:
		unsigned int MAX;		// maximum integer random number
		float invMAX;	// floating point inverse of MAX
		double invDMAX;	// double invers of MAX			
	};



inline RandomSource::~RandomSource() {
    // does nothing
    // exists to ensure that subclass destructors are called
    }



#endif