OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/rand_util.h" | 5 #include "base/rand_util.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/string_util.h" | 13 #include "base/strings/string_util.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 int RandInt(int min, int max) { | 17 int RandInt(int min, int max) { |
18 DCHECK_LE(min, max); | 18 DCHECK_LE(min, max); |
19 | 19 |
20 uint64 range = static_cast<uint64>(max) - min + 1; | 20 uint64 range = static_cast<uint64>(max) - min + 1; |
21 int result = min + static_cast<int>(base::RandGenerator(range)); | 21 int result = min + static_cast<int>(base::RandGenerator(range)); |
22 DCHECK_GE(result, min); | 22 DCHECK_GE(result, min); |
23 DCHECK_LE(result, max); | 23 DCHECK_LE(result, max); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 std::string RandBytesAsString(size_t length) { | 73 std::string RandBytesAsString(size_t length) { |
74 DCHECK_GT(length, 0u); | 74 DCHECK_GT(length, 0u); |
75 std::string result; | 75 std::string result; |
76 RandBytes(WriteInto(&result, length + 1), length); | 76 RandBytes(WriteInto(&result, length + 1), length); |
77 return result; | 77 return result; |
78 } | 78 } |
79 | 79 |
80 } // namespace base | 80 } // namespace base |
OLD | NEW |