From: khizmax Date: Tue, 31 May 2016 06:08:01 +0000 (+0300) Subject: Replaced rand() with std::rand() X-Git-Tag: v2.2.0~239 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f932991cfbf0a6529df58d3094e61d46a6ea194e;p=libcds.git Replaced rand() with std::rand() --- diff --git a/cds/details/bitop_generic.h b/cds/details/bitop_generic.h index 833732b1..38a1dd49 100644 --- a/cds/details/bitop_generic.h +++ b/cds/details/bitop_generic.h @@ -31,7 +31,8 @@ #ifndef CDSLIB_DETAILS_BITOP_GENERIC_H #define CDSLIB_DETAILS_BITOP_GENERIC_H -#include // rand() +#include // rand() + namespace cds { namespace bitop { namespace platform { // Return true if x = 2 ** k, k >= 0 @@ -277,7 +278,7 @@ namespace cds { //static uint32_t xRandom = 2463534242UL ; //rand() | 0x0100 ; // must be nonzero //uint32_t x = xRandom; if ( !x ) - x = ((rand() + 1) << 16) + rand() + 1; + x = (( std::rand() + 1) << 16 ) + std::rand() + 1; x ^= x << 13; x ^= x >> 15; return x ^= x << 5; diff --git a/cds/opt/options.h b/cds/opt/options.h index c2d39f3e..82b0a1fc 100644 --- a/cds/opt/options.h +++ b/cds/opt/options.h @@ -38,7 +38,7 @@ 2011.01.23 khizmax Created */ -#include // rand, srand +#include // rand, srand #include #include @@ -869,16 +869,16 @@ namespace cds { namespace opt { struct c_rand { typedef unsigned int result_type; ///< Result type - /// Constructor initializes object calling \p srand() + /// Constructor initializes object calling \p std::srand() c_rand() { - srand(1); + std::srand(1); } - /// Returns next random number calling \p rand() + /// Returns next random number calling \p std::rand() result_type operator()() { - return (result_type) rand(); + return (result_type) std::rand(); } }; diff --git a/cds/opt/permutation.h b/cds/opt/permutation.h index 58b2bf77..46a21472 100644 --- a/cds/opt/permutation.h +++ b/cds/opt/permutation.h @@ -31,7 +31,7 @@ #ifndef CDSLIB_OPT_PERMUTATION_H #define CDSLIB_OPT_PERMUTATION_H -#include // rand, srand +#include // rand, srand #include #include // std::shuffle #include // std::iota @@ -146,7 +146,7 @@ namespace cds { namespace opt { /// Resets the generator to produce new sequence void reset() { - m_nCur = m_nStart = integer_type( rand() ) % m_nMod; + m_nCur = m_nStart = integer_type( std::rand() ) % m_nMod; } }; @@ -204,7 +204,7 @@ namespace cds { namespace opt { /// Resets the generator to produce new sequence void reset() { - m_nCur = m_nStart = integer_type( rand() ) & m_nMask; + m_nCur = m_nStart = integer_type( std::rand() ) & m_nMask; } }; diff --git a/test/stress/queue/random.cpp b/test/stress/queue/random.cpp index 65b81a26..f444f636 100644 --- a/test/stress/queue/random.cpp +++ b/test/stress/queue/random.cpp @@ -89,7 +89,7 @@ namespace { value_type node; while ( m_nPushCount < nTotalPush ) { - if ( (rand() & 3) != 3 ) { + if ( ( std::rand() & 3) != 3 ) { node.nThread = id(); node.nNo = ++m_nPushCount; if ( !m_Queue.push( node )) { diff --git a/test/unit/misc/split_bitstring.cpp b/test/unit/misc/split_bitstring.cpp index a362a332..d5d58f0c 100644 --- a/test/unit/misc/split_bitstring.cpp +++ b/test/unit/misc/split_bitstring.cpp @@ -108,7 +108,7 @@ namespace { while ( splitter ) { ASSERT_FALSE( splitter.eos() ); ASSERT_FALSE( !splitter ); - int bits = rand() % 16; + int bits = std::rand() % 16; res = res + ( splitter.safe_cut( bits ) << shift ); shift += bits; } @@ -180,7 +180,7 @@ namespace { while ( splitter ) { ASSERT_FALSE( splitter.eos() ); ASSERT_FALSE( !splitter ); - int bits = rand() % 16; + int bits = std::rand() % 16; res = (res << bits) + splitter.safe_cut( bits ); } ASSERT_TRUE( splitter.eos() ); @@ -234,7 +234,7 @@ namespace { while ( splitter ) { ASSERT_FALSE( splitter.eos() ); ASSERT_FALSE( !splitter ); - int bits = rand() % 16; + int bits = std::rand() % 16; res = res + ( static_cast(splitter.safe_cut( bits )) << shift ); shift += bits; } @@ -288,7 +288,7 @@ namespace { while ( splitter ) { ASSERT_FALSE( splitter.eos() ); ASSERT_FALSE( !splitter ); - int bits = rand() % 16; + int bits = std::rand() % 16; res = (res << bits) + splitter.safe_cut( bits ); } ASSERT_TRUE( splitter.eos() );