blob: 43b8917f5cbb2c5f7c7222ae26cbf33002b45cbd (
plain)
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
|
/*
* Copyright (C) 2007-2012 Xagasoft, All rights reserved.
*
* This file is part of the libbu++ library and is released under the
* terms of the license contained in the file LICENSE.
*/
#ifndef BU_RANDOM_H
#define BU_RANDOM_H
#include "bu/singleton.h"
#include <stdint.h>
namespace Bu
{
class RandomBase;
class Random : public Bu::Singleton<Bu::Random>
{
friend class Bu::Singleton<Bu::Random>;
private:
Random();
virtual ~Random();
public:
template<typename cl>
static void setGenerator()
{
delete getInstance().pGen;
getInstance().pGen = new cl();
}
template<typename cl, typename t1>
static void setGenerator( t1 p1 )
{
delete getInstance().pGen;
getInstance().pGen = new cl( p1 );
}
template<typename cl, typename t1, typename t2>
static void setGenerator( t1 p1, t2 p2 )
{
delete getInstance().pGen;
getInstance().pGen = new cl( p1, p2 );
}
RandomBase &getGenerator() { return *pGen; }
static void seed( int32_t iSeed );
static int32_t rand();
static int32_t rand( int32_t iMax );
static int32_t rand( int32_t iMin, int32_t iMax );
static double randNorm();
private:
void checkInit();
private:
Bu::RandomBase *pGen;
};
};
#endif
|