aboutsummaryrefslogtreecommitdiff
path: root/src/experimental
diff options
context:
space:
mode:
Diffstat (limited to 'src/experimental')
-rw-r--r--src/experimental/random.cpp32
-rw-r--r--src/experimental/random.h59
-rw-r--r--src/experimental/randombase.cpp16
-rw-r--r--src/experimental/randombase.h25
-rw-r--r--src/experimental/randombasic.cpp31
-rw-r--r--src/experimental/randombasic.h29
-rw-r--r--src/experimental/randomcmwc.cpp52
-rw-r--r--src/experimental/randomcmwc.h29
-rw-r--r--src/experimental/randomsystem.cpp40
-rw-r--r--src/experimental/randomsystem.h37
10 files changed, 0 insertions, 350 deletions
diff --git a/src/experimental/random.cpp b/src/experimental/random.cpp
deleted file mode 100644
index 725948a..0000000
--- a/src/experimental/random.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
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#include "bu/random.h"
8
9#include "bu/randombasic.h"
10
11Bu::Random::Random() :
12 pGen( NULL )
13{
14 pGen = new RandomBasic();
15}
16
17Bu::Random::~Random()
18{
19 delete pGen;
20 pGen = NULL;
21}
22
23int32_t Bu::Random::rand()
24{
25 return getInstance().pGen->rand();
26}
27
28void Bu::Random::seed( int32_t iSeed )
29{
30 getInstance().pGen->seed( iSeed );
31}
32
diff --git a/src/experimental/random.h b/src/experimental/random.h
deleted file mode 100644
index ba26f21..0000000
--- a/src/experimental/random.h
+++ /dev/null
@@ -1,59 +0,0 @@
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
diff --git a/src/experimental/randombase.cpp b/src/experimental/randombase.cpp
deleted file mode 100644
index 6514df3..0000000
--- a/src/experimental/randombase.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
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#include "bu/randombase.h"
8
9Bu::RandomBase::RandomBase()
10{
11}
12
13Bu::RandomBase::~RandomBase()
14{
15}
16
diff --git a/src/experimental/randombase.h b/src/experimental/randombase.h
deleted file mode 100644
index aff1d45..0000000
--- a/src/experimental/randombase.h
+++ /dev/null
@@ -1,25 +0,0 @@
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_BASE_H
8#define BU_RANDOM_BASE_H
9
10#include <stdint.h>
11
12namespace Bu
13{
14 class RandomBase
15 {
16 public:
17 RandomBase();
18 virtual ~RandomBase();
19
20 virtual void seed( int32_t iSeed )=0;
21 virtual int32_t rand()=0;
22 };
23};
24
25#endif
diff --git a/src/experimental/randombasic.cpp b/src/experimental/randombasic.cpp
deleted file mode 100644
index ac591be..0000000
--- a/src/experimental/randombasic.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
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
8#include "bu/randombasic.h"
9
10Bu::RandomBasic::RandomBasic() :
11 a( 6364136223846793005 ),
12 c( 1442695040888963407 ),
13 x( 0 )
14{
15}
16
17Bu::RandomBasic::~RandomBasic()
18{
19}
20
21void Bu::RandomBasic::seed( int32_t iSeed )
22{
23 c = iSeed;
24}
25
26int32_t Bu::RandomBasic::rand()
27{
28 x = (a*x + c);
29 return (int32_t)x;
30}
31
diff --git a/src/experimental/randombasic.h b/src/experimental/randombasic.h
deleted file mode 100644
index a53e16f..0000000
--- a/src/experimental/randombasic.h
+++ /dev/null
@@ -1,29 +0,0 @@
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_BASIC_H
8#define BU_RANDOM_BASIC_H
9
10#include "bu/randombase.h"
11
12namespace Bu
13{
14 class RandomBasic : public RandomBase
15 {
16 public:
17 RandomBasic();
18 virtual ~RandomBasic();
19
20 virtual void seed( int32_t iSeed );
21
22 virtual int32_t rand();
23
24 private:
25 int64_t a, c, x;
26 };
27};
28
29#endif
diff --git a/src/experimental/randomcmwc.cpp b/src/experimental/randomcmwc.cpp
deleted file mode 100644
index a4e807e..0000000
--- a/src/experimental/randomcmwc.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
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
8#include "bu/randomcmwc.h"
9
10#define PHI 0x9e3779b9
11
12Bu::RandomCmwc::RandomCmwc() :
13 q( 0 ),
14 c( 362436 )
15{
16 q = new uint32_t[4096];
17}
18
19Bu::RandomCmwc::~RandomCmwc()
20{
21 delete[] q;
22}
23
24void Bu::RandomCmwc::seed( int32_t iSeed )
25{
26 int i;
27
28 q[0] = iSeed;
29 q[1] = iSeed + PHI;
30 q[2] = iSeed + PHI + PHI;
31
32 for (i = 3; i < 4096; i++)
33 q[i] = q[i - 3] ^ q[i - 2] ^ PHI ^ i;
34}
35
36int32_t Bu::RandomCmwc::rand()
37{
38 uint64_t t, a = 18782LL;
39 static uint32_t i = 4095;
40 uint32_t x, r = 0xfffffffe;
41 i = (i + 1) & 4095;
42 t = a * q[i] + c;
43 c = (t >> 32);
44 x = t + c;
45 if( x < c )
46 {
47 x++;
48 c++;
49 }
50 return (q[i] = r - x);
51}
52
diff --git a/src/experimental/randomcmwc.h b/src/experimental/randomcmwc.h
deleted file mode 100644
index 747eb6a..0000000
--- a/src/experimental/randomcmwc.h
+++ /dev/null
@@ -1,29 +0,0 @@
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_CMWC_H
8#define BU_RANDOM_CMWC_H
9
10#include "bu/randombase.h"
11
12namespace Bu
13{
14 class RandomCmwc : public RandomBase
15 {
16 public:
17 RandomCmwc();
18 virtual ~RandomCmwc();
19
20 virtual void seed( int32_t iSeed );
21
22 virtual int32_t rand();
23
24 private:
25 uint32_t *q, c;
26 };
27};
28
29#endif
diff --git a/src/experimental/randomsystem.cpp b/src/experimental/randomsystem.cpp
deleted file mode 100644
index 0501587..0000000
--- a/src/experimental/randomsystem.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
1#include "bu/randomsystem.h"
2#include "bu/file.h"
3
4Bu::RandomSystem::RandomSystem( Type eType ) :
5 eType( eType ),
6 pSrc( 0 )
7{
8 switch( eType )
9 {
10 case Bu::RandomSystem::Fast:
11 pSrc = new Bu::File("/dev/urandom", Bu::File::Read );
12 break;
13
14 case Bu::RandomSystem::Good:
15 pSrc = new Bu::File("/dev/random", Bu::File::Read );
16 break;
17 }
18}
19
20Bu::RandomSystem::~RandomSystem()
21{
22 delete pSrc;
23}
24
25void Bu::RandomSystem::seed( int32_t /*iSeed*/ )
26{
27 // Seed really has no effect here...
28 // on linux, if we were root, we could write data to random/urandom to
29 // perturb the data, but it's not necesarry
30}
31
32int32_t Bu::RandomSystem::rand()
33{
34 if( !pSrc )
35 throw Bu::ExceptionBase("Not initialized");
36 int32_t i;
37 pSrc->read( &i, sizeof(int32_t) );
38 return i;
39}
40
diff --git a/src/experimental/randomsystem.h b/src/experimental/randomsystem.h
deleted file mode 100644
index 7106d58..0000000
--- a/src/experimental/randomsystem.h
+++ /dev/null
@@ -1,37 +0,0 @@
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_SYSTEM_H
8#define BU_RANDOM_SYSTEM_H
9
10#include "bu/randombase.h"
11
12namespace Bu
13{
14 class File;
15 class RandomSystem : public RandomBase
16 {
17 public:
18 enum Type
19 {
20 Fast,
21 Good
22 };
23
24 RandomSystem( Type eType=Fast );
25 virtual ~RandomSystem();
26
27 virtual void seed( int32_t iSeed );
28
29 virtual int32_t rand();
30
31 private:
32 Type eType;
33 File *pSrc;
34 };
35};
36
37#endif