Skip to content
Permalink
Browse files

fix mersenne-twister warnings

  • Loading branch information
jef-n committed Jan 23, 2014
1 parent 6bbd17c commit c38fadbaf2ba6d1bc9a8e106f324d73a12716a39
@@ -1,4 +1,4 @@
/*
/*
* The Mersenne Twister pseudo-random number generator (PRNG)
*
* This is an implementation of fast PRNG called MT19937,
@@ -14,7 +14,7 @@
*
* Written by Christian Stigen Larsen
* http://csl.sublevel3.org
*
*
* Distributed under the modified BSD license.
*
* 2012-01-11
@@ -40,7 +40,7 @@ static unsigned index = 0;
#define L31(x) (0x7FFFFFFF & x) // 31 Least Significant Bits
#define ODD(x) (x & 1) // Check if number is odd

#define UINT32_MAX std::numeric_limits<uint32_t>::max()
#define MD_UINT32_MAX std::numeric_limits<uint32_t>::max()

static inline void generate_numbers()
{
@@ -170,10 +170,10 @@ extern "C" int mt_rand()
* PORTABILITY WARNING:
*
* rand_u32() uses all 32-bits for the pseudo-random number,
* but rand() must return a number from 0 ... RAND_MAX.
* but rand() must return a number from 0 ... MD_RAND_MAX.
*
* We'll just assume that rand() only uses 31 bits worth of
* data, and that we're on a two's complement system.
* data, and that we're on a two's complement system.
*
* So, to output an integer compatible with rand(), we have
* two options: Either mask off the highest (32nd) bit, or
@@ -191,32 +191,32 @@ extern "C" void mt_srand(unsigned value)

extern "C" float randf_cc()
{
return static_cast<float>(rand_u32())/UINT32_MAX;
return static_cast<float>(rand_u32())/MD_UINT32_MAX;
}

extern "C" float randf_co()
{
return static_cast<float>(rand_u32())/(UINT32_MAX+1.0f);
return static_cast<float>(rand_u32())/(MD_UINT32_MAX+1.0f);
}

extern "C" float randf_oo()
{
return (static_cast<float>(rand_u32())+0.5f)/(UINT32_MAX+1.0f);
return (static_cast<float>(rand_u32())+0.5f)/(MD_UINT32_MAX+1.0f);
}

extern "C" double randd_cc()
{
return static_cast<double>(rand_u32())/UINT32_MAX;
return static_cast<double>(rand_u32())/MD_UINT32_MAX;
}

extern "C" double randd_co()
{
return static_cast<double>(rand_u32())/(UINT32_MAX+1.0);
return static_cast<double>(rand_u32())/(MD_UINT32_MAX+1.0);
}

extern "C" double randd_oo()
{
return (static_cast<double>(rand_u32())+0.5)/(UINT32_MAX+1.0);
return (static_cast<double>(rand_u32())+0.5)/(MD_UINT32_MAX+1.0);
}

extern "C" uint64_t rand_u64()
@@ -1,4 +1,4 @@
/*
/*
* The Mersenne Twister pseudo-random number generator (PRNG)
*
* This is an implementation of fast PRNG called MT19937,
@@ -32,7 +32,7 @@ extern "C" {
/*
* Maximum number you can get from rand().
*/
#define RAND_MAX std::numeric_limits<int32_t>::max()
#define MD_RAND_MAX std::numeric_limits<int32_t>::max()

/*
* Initialize the number generator with given seed.
@@ -41,13 +41,13 @@ extern "C" {
void mt_srand(unsigned seed_value);

/*
* Extract a pseudo-random integer in the range 0 ... RAND_MAX.
* Extract a pseudo-random integer in the range 0 ... MD_RAND_MAX.
* (LIBC REPLACEMENT FUNCTION)
*/
int mt_rand();

/*
* Extract a pseudo-random unsigned 32-bit integer in the range 0 ... UINT32_MAX
* Extract a pseudo-random unsigned 32-bit integer in the range 0 ... MD_UINT32_MAX
*/
uint32_t rand_u32();

@@ -105,8 +105,8 @@ void QgsPointSample::addSamplePoints( QgsFeature& inputFeature, QgsVectorFileWri

while ( nIterations < maxIterations && points < nPoints )
{
randX = (( double )mt_rand() / RAND_MAX ) * geomRect.width() + geomRect.xMinimum();
randY = (( double )mt_rand() / RAND_MAX ) * geomRect.height() + geomRect.yMinimum();
randX = (( double )mt_rand() / MD_RAND_MAX ) * geomRect.width() + geomRect.xMinimum();
randY = (( double )mt_rand() / MD_RAND_MAX ) * geomRect.height() + geomRect.yMinimum();
QgsPoint randPoint( randX, randY );
QgsGeometry* ptGeom = QgsGeometry::fromPoint( randPoint );
if ( ptGeom->within( geom ) && checkMinDistance( randPoint, sIndex, minDistance, pointMapForFeature ) )
@@ -188,7 +188,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )

while ( nCreatedTransects < nTransects && nIterations < nMaxIterations )
{
double randomPosition = (( double )mt_rand() / RAND_MAX ) * clippedBaseline->length();
double randomPosition = (( double )mt_rand() / MD_RAND_MAX ) * clippedBaseline->length();
QgsGeometry* samplePoint = clippedBaseline->interpolate( randomPosition );
++nIterations;
if ( !samplePoint )

0 comments on commit c38fadb

Please sign in to comment.
You can’t perform that action at this time.