summaryrefslogtreecommitdiff
path: root/src/mongo/platform/random_test.cpp
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2012-11-16 14:38:39 -0500
committerEric Milkie <milkie@10gen.com>2012-11-16 14:38:39 -0500
commit72e82c6c1ed149bdabc8de4207c69856f3f7e86e (patch)
tree100241b1eeb5d4e75de2a2adebb594e0e00dd84c /src/mongo/platform/random_test.cpp
parent61ddf5889de7a3768be43d165d975918cca304f5 (diff)
downloadmongo-72e82c6c1ed149bdabc8de4207c69856f3f7e86e.tar.gz
use xorshift for PseudoRandom on all platforms
Diffstat (limited to 'src/mongo/platform/random_test.cpp')
-rw-r--r--src/mongo/platform/random_test.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/mongo/platform/random_test.cpp b/src/mongo/platform/random_test.cpp
index 1b8d4f64ee8..1f93e78f31f 100644
--- a/src/mongo/platform/random_test.cpp
+++ b/src/mongo/platform/random_test.cpp
@@ -25,25 +25,47 @@
namespace mongo {
TEST( RandomTest, Seed1 ) {
-#ifndef _WIN32
PseudoRandom a( 12 );
PseudoRandom b( 12 );
for ( int i = 0; i < 100; i++ ) {
ASSERT_EQUALS( a.nextInt32(), b.nextInt32() );
}
-#endif
}
TEST( RandomTest, Seed2 ) {
-#ifndef _WIN32
PseudoRandom a( 12 );
PseudoRandom b( 12 );
for ( int i = 0; i < 100; i++ ) {
ASSERT_EQUALS( a.nextInt64(), b.nextInt64() );
}
-#endif
+ }
+
+ TEST( RandomTest, Seed3 ) {
+ PseudoRandom a( 11 );
+ PseudoRandom b( 12 );
+
+ ASSERT_NOT_EQUALS( a.nextInt32(), b.nextInt32() );
+ }
+
+ TEST( RandomTest, Seed4 ) {
+ PseudoRandom a( 11 );
+ std::set<int32_t> s;
+ for ( int i = 0; i < 100; i++ ) {
+ s.insert( a.nextInt32() );
+ }
+ ASSERT_EQUALS( 100U, s.size() );
+ }
+
+ TEST( RandomTest, Seed5 ) {
+ const int64_t seed = 0xCC453456FA345FABLL;
+ PseudoRandom a(seed);
+ std::set<int32_t> s;
+ for ( int i = 0; i < 100; i++ ) {
+ s.insert( a.nextInt32() );
+ }
+ ASSERT_EQUALS( 100U, s.size() );
}
TEST( RandomTest, R1 ) {