Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1221)

Unified Diff: third_party/re2/util/random.cc

Issue 10575037: Include RE2 library (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Less intrusive fix for Android Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/re2/util/random.h ('k') | third_party/re2/util/rune.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/re2/util/random.cc
diff --git a/third_party/re2/util/random.cc b/third_party/re2/util/random.cc
new file mode 100644
index 0000000000000000000000000000000000000000..49d6195876a31aaf5e3a0c7b0f2d16bbba7c64a1
--- /dev/null
+++ b/third_party/re2/util/random.cc
@@ -0,0 +1,34 @@
+// Copyright 2005-2009 The RE2 Authors. All Rights Reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Modified from Google perftools's tcmalloc_unittest.cc.
+
+#include "util/random.h"
+
+namespace re2 {
+
+int32 ACMRandom::Next() {
+ const int32 M = 2147483647L; // 2^31-1
+ const int32 A = 16807;
+ // In effect, we are computing seed_ = (seed_ * A) % M, where M = 2^31-1
+ uint32 lo = A * (int32)(seed_ & 0xFFFF);
+ uint32 hi = A * (int32)((uint32)seed_ >> 16);
+ lo += (hi & 0x7FFF) << 16;
+ if (lo > M) {
+ lo &= M;
+ ++lo;
+ }
+ lo += hi >> 15;
+ if (lo > M) {
+ lo &= M;
+ ++lo;
+ }
+ return (seed_ = (int32) lo);
+}
+
+int32 ACMRandom::Uniform(int32 n) {
+ return Next() % n;
+}
+
+} // namespace re2
« no previous file with comments | « third_party/re2/util/random.h ('k') | third_party/re2/util/rune.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698