diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-05-23 00:39:31 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-05-23 00:39:31 +0000 |
commit | 20ee81a7b2d44ec985e99b4ee1bcd08fa25175d3 (patch) | |
tree | ec6174abd3a21f8d803d26267f9c03ddc468746e | |
parent | ce793e31f387c0715fa5b50c20e06510cc3e95ff (diff) | |
download | libbu++-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 '')
-rw-r--r-- | src/stable/file.cpp | 1 | ||||
-rw-r--r-- | src/stable/random.cpp | 19 | ||||
-rw-r--r-- | src/stable/random.h | 5 | ||||
-rw-r--r-- | src/stable/randombase.cpp | 15 | ||||
-rw-r--r-- | src/stable/randombase.h | 3 |
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 | ||
191 | Bu::File Bu::File::tempFile( Bu::String &sName ) | 191 | Bu::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 | ||
23 | void Bu::Random::seed( int32_t iSeed ) | ||
24 | { | ||
25 | getInstance().pGen->seed( iSeed ); | ||
26 | } | ||
27 | |||
23 | int32_t Bu::Random::rand() | 28 | int32_t Bu::Random::rand() |
24 | { | 29 | { |
25 | return getInstance().pGen->rand(); | 30 | return getInstance().pGen->rand(); |
26 | } | 31 | } |
27 | 32 | ||
28 | void Bu::Random::seed( int32_t iSeed ) | 33 | int32_t Bu::Random::rand( int32_t iMax ) |
29 | { | 34 | { |
30 | getInstance().pGen->seed( iSeed ); | 35 | return getInstance().pGen->rand( iMax ); |
36 | } | ||
37 | |||
38 | int32_t Bu::Random::rand( int32_t iMin, int32_t iMax ) | ||
39 | { | ||
40 | return getInstance().pGen->rand( iMin, iMax ); | ||
41 | } | ||
42 | |||
43 | double 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 | ||
17 | int32_t Bu::RandomBase::rand( int32_t iMax ) | ||
18 | { | ||
19 | return rand( 0, iMax ); | ||
20 | } | ||
21 | |||
22 | int32_t Bu::RandomBase::rand( int32_t iMin, int32_t iMax ) | ||
23 | { | ||
24 | return iMin+(randNorm()*(iMax-iMin)); | ||
25 | } | ||
26 | |||
27 | double 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 | ||