OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator); | 25 // std::random_shuffle(myvector.begin(), myvector.end(), base::RandGenerator); |
26 BASE_EXPORT uint64 RandGenerator(uint64 range); | 26 BASE_EXPORT uint64 RandGenerator(uint64 range); |
27 | 27 |
28 // Returns a random double in range [0, 1). Thread-safe. | 28 // Returns a random double in range [0, 1). Thread-safe. |
29 BASE_EXPORT double RandDouble(); | 29 BASE_EXPORT double RandDouble(); |
30 | 30 |
31 // Given input |bits|, convert with maximum precision to a double in | 31 // Given input |bits|, convert with maximum precision to a double in |
32 // the range [0, 1). Thread-safe. | 32 // the range [0, 1). Thread-safe. |
33 BASE_EXPORT double BitsToOpenEndedUnitInterval(uint64 bits); | 33 BASE_EXPORT double BitsToOpenEndedUnitInterval(uint64 bits); |
34 | 34 |
35 // Fills |output_length| bytes of |output| with cryptographically strong random | 35 // Fills |output_length| bytes of |output| with random data. |
36 // data. | 36 // Use crypto/random for cryptographically random data instead of this function. |
37 BASE_EXPORT void RandBytes(void* output, size_t output_length); | 37 BASE_EXPORT void RandBytes(void* output, size_t output_length); |
38 | 38 |
39 // Fills a string of length |length| with with cryptographically strong random | 39 // Fills a string of length |length| with with random data and returns it. |
40 // data and returns it. |length| should be nonzero. | 40 // |length| should be nonzero. |
| 41 // |
| 42 // Use crypto/random for cryptographically random data instead of this function. |
41 // | 43 // |
42 // Note that this is a variation of |RandBytes| with a different return type. | 44 // Note that this is a variation of |RandBytes| with a different return type. |
43 BASE_EXPORT std::string RandBytesAsString(size_t length); | 45 BASE_EXPORT std::string RandBytesAsString(size_t length); |
44 | 46 |
45 #ifdef OS_POSIX | 47 #ifdef OS_POSIX |
46 BASE_EXPORT int GetUrandomFD(); | 48 BASE_EXPORT int GetUrandomFD(); |
47 #endif | 49 #endif |
48 | 50 |
49 } // namespace base | 51 } // namespace base |
50 | 52 |
51 #endif // BASE_RAND_UTIL_H_ | 53 #endif // BASE_RAND_UTIL_H_ |
OLD | NEW |