fixed GH #2217: UUIDGenerator should allow random seed

This commit is contained in:
Günter Obiltschnig 2020-01-21 21:30:48 +01:00
parent 71585b7daa
commit 2327592bab
2 changed files with 31 additions and 8 deletions

View File

@ -78,6 +78,13 @@ public:
/// The UUID::version() method can be used to determine the actual kind of
/// the UUID generated.
void seed(UInt32 n);
/// Seeds the internal pseudo random generator for time-based UUIDs with the given seed.
void seed();
/// Seeds the internal pseudo random generator used for time-based UUIDs
/// with a random seed obtained from a RandomInputStream.
static UUIDGenerator& defaultGenerator();
/// Returns a reference to the default UUIDGenerator.

View File

@ -136,6 +136,22 @@ UUID UUIDGenerator::createOne()
}
void UUIDGenerator::seed()
{
Poco::FastMutex::ScopedLock lock(_mutex);
_random.seed();
}
void UUIDGenerator::seed(UInt32 n)
{
Poco::FastMutex::ScopedLock lock(_mutex);
_random.seed(n);
}
namespace
{
static SingletonHolder<UUIDGenerator> sh;