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

Unified Diff: base/rand_util.cc

Issue 3053050: Add RandomNumberGenerator adapter to base/rand_util.h (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Compile on Windows, too... Created 10 years, 4 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
Index: base/rand_util.cc
diff --git a/base/rand_util.cc b/base/rand_util.cc
index 8480c827f15fac62dd088027dee3a506cad07ad9..0576c94355a312e09699a147a1b3a42da50715fb 100644
--- a/base/rand_util.cc
+++ b/base/rand_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,9 +16,8 @@ namespace base {
int RandInt(int min, int max) {
DCHECK(min <= max);
- uint64 range = static_cast<int64>(max) - min + 1;
- uint64 number = base::RandUint64();
- int result = min + static_cast<int>(number % range);
+ uint64 range = static_cast<uint64>(max) - min + 1;
+ int result = min + static_cast<int>(base::RandGenerator(range));
DCHECK(result >= min && result <= max);
return result;
}
@@ -37,4 +36,9 @@ double RandDouble() {
return result;
}
+uint64 RandGenerator(uint64 max) {
+ DCHECK(max > 0);
+ return base::RandUint64() % max;
+}
+
} // namespace base
« base/rand_util.h ('K') | « base/rand_util.h ('k') | base/rand_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698