Skip to content

Commit

Permalink
fix mersenne-twister warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 23, 2014
1 parent 6bbd17c commit c38fadb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions src/analysis/vector/mersenne-twister.cpp
@@ -1,4 +1,4 @@
/*
/*
* The Mersenne Twister pseudo-random number generator (PRNG)
*
* This is an implementation of fast PRNG called MT19937,
Expand All @@ -14,7 +14,7 @@
*
* Written by Christian Stigen Larsen
* http://csl.sublevel3.org
*
*
* Distributed under the modified BSD license.
*
* 2012-01-11
Expand All @@ -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()
{
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions src/analysis/vector/mersenne-twister.h
@@ -1,4 +1,4 @@
/*
/*
* The Mersenne Twister pseudo-random number generator (PRNG)
*
* This is an implementation of fast PRNG called MT19937,
Expand Down Expand Up @@ -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.
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/qgspointsample.cpp
Expand Up @@ -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 ) )
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/vector/qgstransectsample.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit c38fadb

Please sign in to comment.