summaryrefslogtreecommitdiff
path: root/src/stable/randomsystem.cpp
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/randomsystem.cpp
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/randomsystem.cpp')
-rw-r--r--src/stable/randomsystem.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/stable/randomsystem.cpp b/src/stable/randomsystem.cpp
new file mode 100644
index 0000000..0501587
--- /dev/null
+++ b/src/stable/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