From 72e82c6c1ed149bdabc8de4207c69856f3f7e86e Mon Sep 17 00:00:00 2001 From: Eric Milkie Date: Fri, 16 Nov 2012 14:38:39 -0500 Subject: use xorshift for PseudoRandom on all platforms --- src/mongo/platform/random_test.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/mongo/platform/random_test.cpp') 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 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 s; + for ( int i = 0; i < 100; i++ ) { + s.insert( a.nextInt32() ); + } + ASSERT_EQUALS( 100U, s.size() ); } TEST( RandomTest, R1 ) { -- cgit v1.2.1