summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-05-23 00:39:31 +0000
committerMike Buland <eichlan@xagasoft.com>2012-05-23 00:39:31 +0000
commit20ee81a7b2d44ec985e99b4ee1bcd08fa25175d3 (patch)
treeec6174abd3a21f8d803d26267f9c03ddc468746e /src
parentce793e31f387c0715fa5b50c20e06510cc3e95ff (diff)
downloadlibbu++-20ee81a7b2d44ec985e99b4ee1bcd08fa25175d3.tar.gz
libbu++-20ee81a7b2d44ec985e99b4ee1bcd08fa25175d3.tar.bz2
libbu++-20ee81a7b2d44ec985e99b4ee1bcd08fa25175d3.tar.xz
libbu++-20ee81a7b2d44ec985e99b4ee1bcd08fa25175d3.zip
We have a nice selection of basic randomness functions now.
Diffstat (limited to 'src')
-rw-r--r--src/stable/file.cpp1
-rw-r--r--src/stable/random.cpp19
-rw-r--r--src/stable/random.h5
-rw-r--r--src/stable/randombase.cpp15
-rw-r--r--src/stable/randombase.h3
5 files changed, 39 insertions, 4 deletions
diff --git a/src/stable/file.cpp b/src/stable/file.cpp
index 81b476d..33420f1 100644
--- a/src/stable/file.cpp
+++ b/src/stable/file.cpp
@@ -190,7 +190,6 @@ void Bu::File::setBlocking( bool bBlocking )
190 190
191Bu::File Bu::File::tempFile( Bu::String &sName ) 191Bu::File Bu::File::tempFile( Bu::String &sName )
192{ 192{
193 uint32_t iX;
194 int iXes; 193 int iXes;
195 for( iXes = sName.getSize()-1; iXes >= 0; iXes-- ) 194 for( iXes = sName.getSize()-1; iXes >= 0; iXes-- )
196 { 195 {
diff --git a/src/stable/random.cpp b/src/stable/random.cpp
index 725948a..63416bf 100644
--- a/src/stable/random.cpp
+++ b/src/stable/random.cpp
@@ -20,13 +20,28 @@ Bu::Random::~Random()
20 pGen = NULL; 20 pGen = NULL;
21} 21}
22 22
23void Bu::Random::seed( int32_t iSeed )
24{
25 getInstance().pGen->seed( iSeed );
26}
27
23int32_t Bu::Random::rand() 28int32_t Bu::Random::rand()
24{ 29{
25 return getInstance().pGen->rand(); 30 return getInstance().pGen->rand();
26} 31}
27 32
28void Bu::Random::seed( int32_t iSeed ) 33int32_t Bu::Random::rand( int32_t iMax )
29{ 34{
30 getInstance().pGen->seed( iSeed ); 35 return getInstance().pGen->rand( iMax );
36}
37
38int32_t Bu::Random::rand( int32_t iMin, int32_t iMax )
39{
40 return getInstance().pGen->rand( iMin, iMax );
41}
42
43double Bu::Random::randNorm()
44{
45 return getInstance().pGen->randNorm();
31} 46}
32 47
diff --git a/src/stable/random.h b/src/stable/random.h
index ba26f21..43b8917 100644
--- a/src/stable/random.h
+++ b/src/stable/random.h
@@ -44,8 +44,11 @@ namespace Bu
44 44
45 RandomBase &getGenerator() { return *pGen; } 45 RandomBase &getGenerator() { return *pGen; }
46 46
47 static int32_t rand();
48 static void seed( int32_t iSeed ); 47 static void seed( int32_t iSeed );
48 static int32_t rand();
49 static int32_t rand( int32_t iMax );
50 static int32_t rand( int32_t iMin, int32_t iMax );
51 static double randNorm();
49 52
50 private: 53 private:
51 void checkInit(); 54 void checkInit();
diff --git a/src/stable/randombase.cpp b/src/stable/randombase.cpp
index 6514df3..71a5c89 100644
--- a/src/stable/randombase.cpp
+++ b/src/stable/randombase.cpp
@@ -14,3 +14,18 @@ Bu::RandomBase::~RandomBase()
14{ 14{
15} 15}
16 16
17int32_t Bu::RandomBase::rand( int32_t iMax )
18{
19 return rand( 0, iMax );
20}
21
22int32_t Bu::RandomBase::rand( int32_t iMin, int32_t iMax )
23{
24 return iMin+(randNorm()*(iMax-iMin));
25}
26
27double Bu::RandomBase::randNorm()
28{
29 return (((uint32_t)rand())&0xfffffffeul)/(double)(0xfffffffful);
30}
31
diff --git a/src/stable/randombase.h b/src/stable/randombase.h
index aff1d45..a5a4f42 100644
--- a/src/stable/randombase.h
+++ b/src/stable/randombase.h
@@ -19,6 +19,9 @@ namespace Bu
19 19
20 virtual void seed( int32_t iSeed )=0; 20 virtual void seed( int32_t iSeed )=0;
21 virtual int32_t rand()=0; 21 virtual int32_t rand()=0;
22 virtual int32_t rand( int32_t iMax );
23 virtual int32_t rand( int32_t iMin, int32_t iMax );
24 virtual double randNorm();
22 }; 25 };
23}; 26};
24 27