Changeset 28:bac3a3382c4a in xplcommon


Ignore:
Timestamp:
01/02/13 08:53:57 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The local socket test program now uses the pseudo-random number generator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/testlocsock.cc

    r21 r28  
    4040#include <xplcommon/WritingBuffer.h>
    4141#include <xplcommon/WaitableEvent.h>
     42#include <xplcommon/PseudoRandom.h>
    4243
    4344#include <cstdlib>
     
    6162using xplcommon::WritingBuffer;
    6263using xplcommon::WaitableEvent;
     64using xplcommon::PseudoRandom;
    6365
    6466using std::min;
     
    7274    static const size_t minToWrite = 2076;
    7375    static const size_t maxToWrite = 1345670;
    74     static const size_t rangeToWrite = maxToWrite - minToWrite;
    7576
    7677    static const size_t reportingInterval = 10000;
    7778
    78     static const int sleepThreshold = static_cast<int>(RAND_MAX * 0.99);
    79     static const int sleepRemainder = RAND_MAX - sleepThreshold;
     79    static const int sleepThreshold = static_cast<int>(PseudoRandom::MAX * 0.99);
     80    static const int sleepRemainder = PseudoRandom::MAX - sleepThreshold;
    8081    static const unsigned minSleep = 10;
    8182    static const unsigned maxSleep = 250;
     
    9293    bool toQuit = false;
    9394
     95    PseudoRandom random(seed);
    9496    while(!toQuit) {
    95 #if TARGET_API_POSIX
    96         int r = rand_r(&seed);
    97 #endif
    98 #if TARGET_API_WIN32
    99         int r = rand();
    100 #endif
    101         size_t toWrite = minToWrite +
    102             static_cast<size_t>( static_cast<double>(r) *
    103                                  rangeToWrite / RAND_MAX );
     97        size_t toWrite = random.nextUnsigned(maxToWrite, minToWrite);
    10498
    10599        size_t lastWriteLength = 0;
     
    204198            }
    205199
    206 #if TARGET_API_POSIX
    207             r = rand_r(&seed);
    208 #endif
    209 #if TARGET_API_WIN32
    210             r = rand();
    211 #endif
     200            int r = random.next();
    212201            if (r>=sleepThreshold) {
    213202                unsigned toSleep = minSleep +
Note: See TracChangeset for help on using the changeset viewer.