aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/randomsystem.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-05-22 16:57:15 +0000
committerMike Buland <eichlan@xagasoft.com>2012-05-22 16:57:15 +0000
commit2295579eb790d6eff6e54e84c01da6de10809a71 (patch)
tree3d8282dedc137fee009f71ff904370537009e504 /src/experimental/randomsystem.cpp
parent690ad7280e655654a3bcca2ca5ced9caacf75c8b (diff)
downloadlibbu++-2295579eb790d6eff6e54e84c01da6de10809a71.tar.gz
libbu++-2295579eb790d6eff6e54e84c01da6de10809a71.tar.bz2
libbu++-2295579eb790d6eff6e54e84c01da6de10809a71.tar.xz
libbu++-2295579eb790d6eff6e54e84c01da6de10809a71.zip
Better win_o ignores. The random number system is pretty much together.
We need a few extra helper functions to cover some other good things, like normalized floating point numbers, etc.
Diffstat (limited to '')
-rw-r--r--src/experimental/randomsystem.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/experimental/randomsystem.cpp b/src/experimental/randomsystem.cpp
new file mode 100644
index 0000000..0501587
--- /dev/null
+++ b/src/experimental/randomsystem.cpp
@@ -0,0 +1,40 @@
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