// // C++ Implementation: rngqueue // // Description: // // // Author: Frank Michler,,, , (C) 2010 // // Copyright: See COPYING file that comes with this distribution // // #include #include "rngqueue.hpp" using namespace std; /** @brief Constructor * */ RngQueue::RngQueue(IRngQueuePool* _RngPool, vector* _FreshRandomNumbers) : mRngQueuePool(_RngPool), mRngNumberVector(_FreshRandomNumbers) { mVectorEnd = mRngNumberVector->end(); mVectorIter = mRngNumberVector->begin(); } RngQueue::~RngQueue() { mRngQueuePool->releaseRngQueue(this); } /** @brief provides a fresh random number. Not reentrant!! Call this member of the same object instance from only one thread! * * @return random number */ double RngQueue::getRandomNumber() { if (mVectorIter == mVectorEnd) { getFreshNumbers(); } double RandomValue = (*mVectorIter); ++mVectorIter; return RandomValue; } void RngQueue::getFreshNumbers() { mRngNumberVector = mRngQueuePool->getRandomNumberVector(this); mVectorEnd = mRngNumberVector->end(); mVectorIter = mRngNumberVector->begin(); }