diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-30 21:07:05 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-30 21:07:05 +0000 |
commit | a74dcaeaa91acee7dde40b9680eb6e0e30df11fd (patch) | |
tree | 41d17386b9ed6f7b4266d3332860c954b64358e9 /base/rand_util.cc | |
parent | bf898dad1b57c6fd436bc8d8c8ef143e3d11755d (diff) | |
download | chromium_src-a74dcaeaa91acee7dde40b9680eb6e0e30df11fd.zip chromium_src-a74dcaeaa91acee7dde40b9680eb6e0e30df11fd.tar.gz chromium_src-a74dcaeaa91acee7dde40b9680eb6e0e30df11fd.tar.bz2 |
Add RandomNumberGenerator adapter to base/rand_util.h
BUG=46679
TEST=none (yet...)
Review URL: http://codereview.chromium.org/3053050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/rand_util.cc')
-rw-r--r-- | base/rand_util.cc | 12 |
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 |