#ifndef CDSLIB_DETAILS_BITOP_GENERIC_H
#define CDSLIB_DETAILS_BITOP_GENERIC_H
-#include <stdlib.h> // rand()
+#include <cstdlib> // rand()
+
namespace cds {
namespace bitop { namespace platform {
// Return true if x = 2 ** k, k >= 0
//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;
2011.01.23 khizmax Created
*/
-#include <stdlib.h> // rand, srand
+#include <cstdlib> // rand, srand
#include <cds/details/aligned_type.h>
#include <cds/user_setup/allocator.h>
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();
}
};
#ifndef CDSLIB_OPT_PERMUTATION_H
#define CDSLIB_OPT_PERMUTATION_H
-#include <stdlib.h> // rand, srand
+#include <cstdlib> // rand, srand
#include <random>
#include <algorithm> // std::shuffle
#include <numeric> // std::iota
/// 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;
}
};
/// 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;
}
};
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 )) {
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;
}
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() );
while ( splitter ) {
ASSERT_FALSE( splitter.eos() );
ASSERT_FALSE( !splitter );
- int bits = rand() % 16;
+ int bits = std::rand() % 16;
res = res + ( static_cast<uint64_t>(splitter.safe_cut( bits )) << shift );
shift += bits;
}
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() );