summaryrefslogtreecommitdiff
path: root/src/SimpleRandomizer.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-03-25 00:28:11 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-03-25 00:28:11 +0900
commitae393329f7adf1c3009219ba703fc7fa2ca98fcd (patch)
tree703ee0f572db91a5007592b355d467e343ed84b7 /src/SimpleRandomizer.cc
parent4d8c17d104ad81b4f5983d0edacefcfc5f868bf8 (diff)
Fixed segmentation fault in open solaris in unit test.
This is due to the fact that the maximum value of random() in open solaris is not RAND_MAX, but (2**31)-1.
Diffstat (limited to 'src/SimpleRandomizer.cc')
-rw-r--r--src/SimpleRandomizer.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/SimpleRandomizer.cc b/src/SimpleRandomizer.cc
index 48a46b96..cdeedde7 100644
--- a/src/SimpleRandomizer.cc
+++ b/src/SimpleRandomizer.cc
@@ -98,14 +98,15 @@ long int SimpleRandomizer::getMaxRandomNumber()
#ifdef __MINGW32__
return INT32_MAX;
#else // !__MINGW32__
+ // TODO Warning: The maximum value of random() in some sytems (e.g.,
+ // Solaris and openbsd) is (2**31)-1.
return RAND_MAX;
#endif // !__MINGW32__
}
long int SimpleRandomizer::getRandomNumber(long int to)
{
-
- return(long int)(((double)to)*getRandomNumber()/(getMaxRandomNumber()+1.0));
+ return getRandomNumber() % to;
}
long int SimpleRandomizer::operator()(long int to)