summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-09-21 19:42:03 (GMT)
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-09-21 19:42:03 (GMT)
commit2534ae201e47986d36d5fab0e523a7f046b8ec1e (patch)
tree70aacac236ddc0e5c5941b7c92970f9b3c743d57 /include
parente5373af0cb9cae249e7bc618cae3483397332895 (diff)
downloadgoogletest-2534ae201e47986d36d5fab0e523a7f046b8ec1e.zip
googletest-2534ae201e47986d36d5fab0e523a7f046b8ec1e.tar.gz
googletest-2534ae201e47986d36d5fab0e523a7f046b8ec1e.tar.bz2
Adds a Random class to support --gtest_shuffle (by Josh Kelley); Makes the scons script build in a deterministic order (by Zhanyong Wan).
Diffstat (limited to 'include')
-rw-r--r--include/gtest/internal/gtest-internal.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h
index 4775524..f5c30fb 100644
--- a/include/gtest/internal/gtest-internal.h
+++ b/include/gtest/internal/gtest-internal.h
@@ -748,6 +748,28 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count);
// A helper for suppressing warnings on unreachable code in some macros.
bool AlwaysTrue();
+// A simple Linear Congruential Generator for generating random
+// numbers with a uniform distribution. Unlike rand() and srand(), it
+// doesn't use global state (and therefore can't interfere with user
+// code). Unlike rand_r(), it's portable. An LCG isn't very random,
+// but it's good enough for our purposes.
+class Random {
+ public:
+ static const UInt32 kMaxRange = 1u << 31;
+
+ explicit Random(UInt32 seed) : state_(seed) {}
+
+ void Reseed(UInt32 seed) { state_ = seed; }
+
+ // Generates a random number from [0, range). Crashes if 'range' is
+ // 0 or greater than kMaxRange.
+ UInt32 Generate(UInt32 range);
+
+ private:
+ UInt32 state_;
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
+};
+
} // namespace internal
} // namespace testing