From ce793e31f387c0715fa5b50c20e06510cc3e95ff Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 22 May 2012 17:15:40 +0000 Subject: 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. --- src/stable/file.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/stable/file.cpp') diff --git a/src/stable/file.cpp b/src/stable/file.cpp index 8d10596..81b476d 100644 --- a/src/stable/file.cpp +++ b/src/stable/file.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "bu/random.h" #include "bu/config.h" @@ -190,7 +191,6 @@ void Bu::File::setBlocking( bool bBlocking ) Bu::File Bu::File::tempFile( Bu::String &sName ) { uint32_t iX; - iX = time( NULL ) + getpid(); int iXes; for( iXes = sName.getSize()-1; iXes >= 0; iXes-- ) { @@ -200,11 +200,11 @@ Bu::File Bu::File::tempFile( Bu::String &sName ) iXes++; if( iXes == sName.getSize() ) throw Bu::ExceptionBase("Invalid temporary filename template."); - for( int iter = 0; iter < 100; iter++ ) + for( int iter = 0; iter < 1000; iter++ ) { for( int j = iXes; j < sName.getSize(); j++ ) { - iX = (1103515245 * iX + 12345); + uint32_t iX = Bu::Random::rand(); sName[j] = ('A'+(iX%26)) | ((iX&0x1000)?(0x20):(0)); } @@ -214,7 +214,7 @@ Bu::File Bu::File::tempFile( Bu::String &sName ) |Bu::File::Create|Bu::File::Exclusive ); } catch(...) { } } - throw Bu::FileException("Failed to create unique temporary file after 100" + throw Bu::FileException("Failed to create unique temporary file after 1000" " iterations."); } -- cgit v1.2.3