Skip to content

Commit c38fadb

Browse files
committed
fix mersenne-twister warnings
1 parent 6bbd17c commit c38fadb

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/analysis/vector/mersenne-twister.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The Mersenne Twister pseudo-random number generator (PRNG)
33
*
44
* This is an implementation of fast PRNG called MT19937,
@@ -14,7 +14,7 @@
1414
*
1515
* Written by Christian Stigen Larsen
1616
* http://csl.sublevel3.org
17-
*
17+
*
1818
* Distributed under the modified BSD license.
1919
*
2020
* 2012-01-11
@@ -40,7 +40,7 @@ static unsigned index = 0;
4040
#define L31(x) (0x7FFFFFFF & x) // 31 Least Significant Bits
4141
#define ODD(x) (x & 1) // Check if number is odd
4242

43-
#define UINT32_MAX std::numeric_limits<uint32_t>::max()
43+
#define MD_UINT32_MAX std::numeric_limits<uint32_t>::max()
4444

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

192192
extern "C" float randf_cc()
193193
{
194-
return static_cast<float>(rand_u32())/UINT32_MAX;
194+
return static_cast<float>(rand_u32())/MD_UINT32_MAX;
195195
}
196196

197197
extern "C" float randf_co()
198198
{
199-
return static_cast<float>(rand_u32())/(UINT32_MAX+1.0f);
199+
return static_cast<float>(rand_u32())/(MD_UINT32_MAX+1.0f);
200200
}
201201

202202
extern "C" float randf_oo()
203203
{
204-
return (static_cast<float>(rand_u32())+0.5f)/(UINT32_MAX+1.0f);
204+
return (static_cast<float>(rand_u32())+0.5f)/(MD_UINT32_MAX+1.0f);
205205
}
206206

207207
extern "C" double randd_cc()
208208
{
209-
return static_cast<double>(rand_u32())/UINT32_MAX;
209+
return static_cast<double>(rand_u32())/MD_UINT32_MAX;
210210
}
211211

212212
extern "C" double randd_co()
213213
{
214-
return static_cast<double>(rand_u32())/(UINT32_MAX+1.0);
214+
return static_cast<double>(rand_u32())/(MD_UINT32_MAX+1.0);
215215
}
216216

217217
extern "C" double randd_oo()
218218
{
219-
return (static_cast<double>(rand_u32())+0.5)/(UINT32_MAX+1.0);
219+
return (static_cast<double>(rand_u32())+0.5)/(MD_UINT32_MAX+1.0);
220220
}
221221

222222
extern "C" uint64_t rand_u64()

src/analysis/vector/mersenne-twister.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The Mersenne Twister pseudo-random number generator (PRNG)
33
*
44
* This is an implementation of fast PRNG called MT19937,
@@ -32,7 +32,7 @@ extern "C" {
3232
/*
3333
* Maximum number you can get from rand().
3434
*/
35-
#define RAND_MAX std::numeric_limits<int32_t>::max()
35+
#define MD_RAND_MAX std::numeric_limits<int32_t>::max()
3636

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

4343
/*
44-
* Extract a pseudo-random integer in the range 0 ... RAND_MAX.
44+
* Extract a pseudo-random integer in the range 0 ... MD_RAND_MAX.
4545
* (LIBC REPLACEMENT FUNCTION)
4646
*/
4747
int mt_rand();
4848

4949
/*
50-
* Extract a pseudo-random unsigned 32-bit integer in the range 0 ... UINT32_MAX
50+
* Extract a pseudo-random unsigned 32-bit integer in the range 0 ... MD_UINT32_MAX
5151
*/
5252
uint32_t rand_u32();
5353

src/analysis/vector/qgspointsample.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ void QgsPointSample::addSamplePoints( QgsFeature& inputFeature, QgsVectorFileWri
105105

106106
while ( nIterations < maxIterations && points < nPoints )
107107
{
108-
randX = (( double )mt_rand() / RAND_MAX ) * geomRect.width() + geomRect.xMinimum();
109-
randY = (( double )mt_rand() / RAND_MAX ) * geomRect.height() + geomRect.yMinimum();
108+
randX = (( double )mt_rand() / MD_RAND_MAX ) * geomRect.width() + geomRect.xMinimum();
109+
randY = (( double )mt_rand() / MD_RAND_MAX ) * geomRect.height() + geomRect.yMinimum();
110110
QgsPoint randPoint( randX, randY );
111111
QgsGeometry* ptGeom = QgsGeometry::fromPoint( randPoint );
112112
if ( ptGeom->within( geom ) && checkMinDistance( randPoint, sIndex, minDistance, pointMapForFeature ) )

src/analysis/vector/qgstransectsample.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
188188

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

0 commit comments

Comments
 (0)