summaryrefslogtreecommitdiffstats
path: root/base/rand_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/rand_util.cc')
-rw-r--r--base/rand_util.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/base/rand_util.cc b/base/rand_util.cc
index 8480c82..0576c94 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