summaryrefslogtreecommitdiff
path: root/src/experimental/randomsystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/experimental/randomsystem.cpp')
-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