mirror of https://github.com/davisking/dlib.git
Gave rand a constructor that takes a seed value.
This commit is contained in:
parent
1b1cf7548c
commit
7f5a22c424
|
@ -36,18 +36,15 @@ namespace dlib
|
|||
rand(
|
||||
)
|
||||
{
|
||||
// prime the generator a bit
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
mt();
|
||||
init();
|
||||
}
|
||||
|
||||
max_val = 0xFFFFFF;
|
||||
max_val *= 0x1000000;
|
||||
max_val += 0xFFFFFF;
|
||||
max_val += 0.01;
|
||||
|
||||
|
||||
has_gaussian = false;
|
||||
next_gaussian = 0;
|
||||
rand (
|
||||
const std::string& seed_value
|
||||
)
|
||||
{
|
||||
init();
|
||||
set_seed(seed_value);
|
||||
}
|
||||
|
||||
virtual ~rand(
|
||||
|
@ -234,6 +231,23 @@ namespace dlib
|
|||
);
|
||||
|
||||
private:
|
||||
|
||||
void init()
|
||||
{
|
||||
// prime the generator a bit
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
mt();
|
||||
|
||||
max_val = 0xFFFFFF;
|
||||
max_val *= 0x1000000;
|
||||
max_val += 0xFFFFFF;
|
||||
max_val += 0.01;
|
||||
|
||||
|
||||
has_gaussian = false;
|
||||
next_gaussian = 0;
|
||||
}
|
||||
|
||||
mt19937 mt;
|
||||
|
||||
std::string seed;
|
||||
|
|
|
@ -34,6 +34,19 @@ namespace dlib
|
|||
- std::bad_alloc
|
||||
!*/
|
||||
|
||||
rand (
|
||||
const std::string& seed_value
|
||||
);
|
||||
/*!
|
||||
ensures
|
||||
- #*this is properly initialized
|
||||
- #get_seed() == seed_value
|
||||
- This version of the constructor is equivalent to using
|
||||
the default constructor and then calling set_seed(seed_value)
|
||||
throws
|
||||
- std::bad_alloc
|
||||
!*/
|
||||
|
||||
virtual ~rand(
|
||||
);
|
||||
/*!
|
||||
|
|
Loading…
Reference in New Issue