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 #ifndef BASE_RAND_UTIL_H_ | 5 #ifndef BASE_RAND_UTIL_H_ |
6 #define BASE_RAND_UTIL_H_ | 6 #define BASE_RAND_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | |
10 | |
9 #include "base/base_api.h" | 11 #include "base/base_api.h" |
10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
11 | 13 |
12 namespace base { | 14 namespace base { |
13 | 15 |
14 // Returns a random number in range [0, kuint64max]. Thread-safe. | 16 // Returns a random number in range [0, kuint64max]. Thread-safe. |
15 BASE_API uint64 RandUint64(); | 17 BASE_API uint64 RandUint64(); |
16 | 18 |
17 // Returns a random number between min and max (inclusive). Thread-safe. | 19 // Returns a random number between min and max (inclusive). Thread-safe. |
18 BASE_API int RandInt(int min, int max); | 20 BASE_API int RandInt(int min, int max); |
19 | 21 |
20 // Returns a random number in range [0, max). Thread-safe. | 22 // Returns a random number in range [0, max). Thread-safe. |
21 // | 23 // |
22 // Note that this can be used as an adapter for std::random_shuffle(): | 24 // Note that this can be used as an adapter for std::random_shuffle(): |
23 // Given a pre-populated |std::vector<int> myvector|, shuffle it as | 25 // Given a pre-populated |std::vector<int> myvector|, shuffle it as |
24 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator); | 26 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator); |
25 BASE_API uint64 RandGenerator(uint64 max); | 27 BASE_API uint64 RandGenerator(uint64 max); |
26 | 28 |
27 // Returns a random double in range [0, 1). Thread-safe. | 29 // Returns a random double in range [0, 1). Thread-safe. |
28 BASE_API double RandDouble(); | 30 BASE_API double RandDouble(); |
29 | 31 |
32 // Returns a random string of the specified length. | |
33 BASE_API std::string RandString(int length); | |
wtc
2011/04/29 18:03:56
The |length| parameter should have the type size_t
| |
34 | |
30 } // namespace base | 35 } // namespace base |
31 | 36 |
32 #endif // BASE_RAND_UTIL_H_ | 37 #endif // BASE_RAND_UTIL_H_ |
OLD | NEW |