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/experimental/random.cpp | 32 --------------------- src/experimental/random.h | 59 --------------------------------------- src/experimental/randombase.cpp | 16 ----------- src/experimental/randombase.h | 25 ----------------- src/experimental/randombasic.cpp | 31 -------------------- src/experimental/randombasic.h | 29 ------------------- src/experimental/randomcmwc.cpp | 52 ---------------------------------- src/experimental/randomcmwc.h | 29 ------------------- src/experimental/randomsystem.cpp | 40 -------------------------- src/experimental/randomsystem.h | 37 ------------------------ 10 files changed, 350 deletions(-) delete mode 100644 src/experimental/random.cpp delete mode 100644 src/experimental/random.h delete mode 100644 src/experimental/randombase.cpp delete mode 100644 src/experimental/randombase.h delete mode 100644 src/experimental/randombasic.cpp delete mode 100644 src/experimental/randombasic.h delete mode 100644 src/experimental/randomcmwc.cpp delete mode 100644 src/experimental/randomcmwc.h delete mode 100644 src/experimental/randomsystem.cpp delete mode 100644 src/experimental/randomsystem.h (limited to 'src/experimental') diff --git a/src/experimental/random.cpp b/src/experimental/random.cpp deleted file mode 100644 index 725948a..0000000 --- a/src/experimental/random.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ -#include "bu/random.h" - -#include "bu/randombasic.h" - -Bu::Random::Random() : - pGen( NULL ) -{ - pGen = new RandomBasic(); -} - -Bu::Random::~Random() -{ - delete pGen; - pGen = NULL; -} - -int32_t Bu::Random::rand() -{ - return getInstance().pGen->rand(); -} - -void Bu::Random::seed( int32_t iSeed ) -{ - getInstance().pGen->seed( iSeed ); -} - diff --git a/src/experimental/random.h b/src/experimental/random.h deleted file mode 100644 index ba26f21..0000000 --- a/src/experimental/random.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ -#ifndef BU_RANDOM_H -#define BU_RANDOM_H - -#include "bu/singleton.h" -#include - -namespace Bu -{ - class RandomBase; - class Random : public Bu::Singleton - { - friend class Bu::Singleton; - private: - Random(); - virtual ~Random(); - - public: - template - static void setGenerator() - { - delete getInstance().pGen; - getInstance().pGen = new cl(); - } - - template - static void setGenerator( t1 p1 ) - { - delete getInstance().pGen; - getInstance().pGen = new cl( p1 ); - } - - template - static void setGenerator( t1 p1, t2 p2 ) - { - delete getInstance().pGen; - getInstance().pGen = new cl( p1, p2 ); - } - - RandomBase &getGenerator() { return *pGen; } - - static int32_t rand(); - static void seed( int32_t iSeed ); - - private: - void checkInit(); - - private: - Bu::RandomBase *pGen; - }; -}; - -#endif - diff --git a/src/experimental/randombase.cpp b/src/experimental/randombase.cpp deleted file mode 100644 index 6514df3..0000000 --- a/src/experimental/randombase.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ -#include "bu/randombase.h" - -Bu::RandomBase::RandomBase() -{ -} - -Bu::RandomBase::~RandomBase() -{ -} - diff --git a/src/experimental/randombase.h b/src/experimental/randombase.h deleted file mode 100644 index aff1d45..0000000 --- a/src/experimental/randombase.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ -#ifndef BU_RANDOM_BASE_H -#define BU_RANDOM_BASE_H - -#include - -namespace Bu -{ - class RandomBase - { - public: - RandomBase(); - virtual ~RandomBase(); - - virtual void seed( int32_t iSeed )=0; - virtual int32_t rand()=0; - }; -}; - -#endif diff --git a/src/experimental/randombasic.cpp b/src/experimental/randombasic.cpp deleted file mode 100644 index ac591be..0000000 --- a/src/experimental/randombasic.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/randombasic.h" - -Bu::RandomBasic::RandomBasic() : - a( 6364136223846793005 ), - c( 1442695040888963407 ), - x( 0 ) -{ -} - -Bu::RandomBasic::~RandomBasic() -{ -} - -void Bu::RandomBasic::seed( int32_t iSeed ) -{ - c = iSeed; -} - -int32_t Bu::RandomBasic::rand() -{ - x = (a*x + c); - return (int32_t)x; -} - diff --git a/src/experimental/randombasic.h b/src/experimental/randombasic.h deleted file mode 100644 index a53e16f..0000000 --- a/src/experimental/randombasic.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ -#ifndef BU_RANDOM_BASIC_H -#define BU_RANDOM_BASIC_H - -#include "bu/randombase.h" - -namespace Bu -{ - class RandomBasic : public RandomBase - { - public: - RandomBasic(); - virtual ~RandomBasic(); - - virtual void seed( int32_t iSeed ); - - virtual int32_t rand(); - - private: - int64_t a, c, x; - }; -}; - -#endif diff --git a/src/experimental/randomcmwc.cpp b/src/experimental/randomcmwc.cpp deleted file mode 100644 index a4e807e..0000000 --- a/src/experimental/randomcmwc.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/randomcmwc.h" - -#define PHI 0x9e3779b9 - -Bu::RandomCmwc::RandomCmwc() : - q( 0 ), - c( 362436 ) -{ - q = new uint32_t[4096]; -} - -Bu::RandomCmwc::~RandomCmwc() -{ - delete[] q; -} - -void Bu::RandomCmwc::seed( int32_t iSeed ) -{ - int i; - - q[0] = iSeed; - q[1] = iSeed + PHI; - q[2] = iSeed + PHI + PHI; - - for (i = 3; i < 4096; i++) - q[i] = q[i - 3] ^ q[i - 2] ^ PHI ^ i; -} - -int32_t Bu::RandomCmwc::rand() -{ - uint64_t t, a = 18782LL; - static uint32_t i = 4095; - uint32_t x, r = 0xfffffffe; - i = (i + 1) & 4095; - t = a * q[i] + c; - c = (t >> 32); - x = t + c; - if( x < c ) - { - x++; - c++; - } - return (q[i] = r - x); -} - diff --git a/src/experimental/randomcmwc.h b/src/experimental/randomcmwc.h deleted file mode 100644 index 747eb6a..0000000 --- a/src/experimental/randomcmwc.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ -#ifndef BU_RANDOM_CMWC_H -#define BU_RANDOM_CMWC_H - -#include "bu/randombase.h" - -namespace Bu -{ - class RandomCmwc : public RandomBase - { - public: - RandomCmwc(); - virtual ~RandomCmwc(); - - virtual void seed( int32_t iSeed ); - - virtual int32_t rand(); - - private: - uint32_t *q, c; - }; -}; - -#endif diff --git a/src/experimental/randomsystem.cpp b/src/experimental/randomsystem.cpp deleted file mode 100644 index 0501587..0000000 --- a/src/experimental/randomsystem.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "bu/randomsystem.h" -#include "bu/file.h" - -Bu::RandomSystem::RandomSystem( Type eType ) : - eType( eType ), - pSrc( 0 ) -{ - switch( eType ) - { - case Bu::RandomSystem::Fast: - pSrc = new Bu::File("/dev/urandom", Bu::File::Read ); - break; - - case Bu::RandomSystem::Good: - pSrc = new Bu::File("/dev/random", Bu::File::Read ); - break; - } -} - -Bu::RandomSystem::~RandomSystem() -{ - delete pSrc; -} - -void Bu::RandomSystem::seed( int32_t /*iSeed*/ ) -{ - // Seed really has no effect here... - // on linux, if we were root, we could write data to random/urandom to - // perturb the data, but it's not necesarry -} - -int32_t Bu::RandomSystem::rand() -{ - if( !pSrc ) - throw Bu::ExceptionBase("Not initialized"); - int32_t i; - pSrc->read( &i, sizeof(int32_t) ); - return i; -} - diff --git a/src/experimental/randomsystem.h b/src/experimental/randomsystem.h deleted file mode 100644 index 7106d58..0000000 --- a/src/experimental/randomsystem.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ -#ifndef BU_RANDOM_SYSTEM_H -#define BU_RANDOM_SYSTEM_H - -#include "bu/randombase.h" - -namespace Bu -{ - class File; - class RandomSystem : public RandomBase - { - public: - enum Type - { - Fast, - Good - }; - - RandomSystem( Type eType=Fast ); - virtual ~RandomSystem(); - - virtual void seed( int32_t iSeed ); - - virtual int32_t rand(); - - private: - Type eType; - File *pSrc; - }; -}; - -#endif -- cgit v1.2.3