aboutsummaryrefslogtreecommitdiff
path: root/src/stable/random.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-05-22 17:15:40 +0000
committerMike Buland <eichlan@xagasoft.com>2012-05-22 17:15:40 +0000
commitce793e31f387c0715fa5b50c20e06510cc3e95ff (patch)
tree5b15972bdcbe7a26933e8158f52b29fb014dc421 /src/stable/random.h
parent2295579eb790d6eff6e54e84c01da6de10809a71 (diff)
downloadlibbu++-ce793e31f387c0715fa5b50c20e06510cc3e95ff.tar.gz
libbu++-ce793e31f387c0715fa5b50c20e06510cc3e95ff.tar.bz2
libbu++-ce793e31f387c0715fa5b50c20e06510cc3e95ff.tar.xz
libbu++-ce793e31f387c0715fa5b50c20e06510cc3e95ff.zip
Moved random to stable, just needs some minor tweaks. But it's already in use
in a couple of core components, including in tempFile name generation.
Diffstat (limited to 'src/stable/random.h')
-rw-r--r--src/stable/random.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/stable/random.h b/src/stable/random.h
new file mode 100644
index 0000000..ba26f21
--- /dev/null
+++ b/src/stable/random.h
@@ -0,0 +1,59 @@
1/*
2 * Copyright (C) 2007-2012 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7#ifndef BU_RANDOM_H
8#define BU_RANDOM_H
9
10#include "bu/singleton.h"
11#include <stdint.h>
12
13namespace Bu
14{
15 class RandomBase;
16 class Random : public Bu::Singleton<Bu::Random>
17 {
18 friend class Bu::Singleton<Bu::Random>;
19 private:
20 Random();
21 virtual ~Random();
22
23 public:
24 template<typename cl>
25 static void setGenerator()
26 {
27 delete getInstance().pGen;
28 getInstance().pGen = new cl();
29 }
30
31 template<typename cl, typename t1>
32 static void setGenerator( t1 p1 )
33 {
34 delete getInstance().pGen;
35 getInstance().pGen = new cl( p1 );
36 }
37
38 template<typename cl, typename t1, typename t2>
39 static void setGenerator( t1 p1, t2 p2 )
40 {
41 delete getInstance().pGen;
42 getInstance().pGen = new cl( p1, p2 );
43 }
44
45 RandomBase &getGenerator() { return *pGen; }
46
47 static int32_t rand();
48 static void seed( int32_t iSeed );
49
50 private:
51 void checkInit();
52
53 private:
54 Bu::RandomBase *pGen;
55 };
56};
57
58#endif
59