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