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 // Note: The random data is cryptographically secure, but use the RNG in crypto/ |
37 // for security-sensitive purposes instead of this function. | |
Ryan Sleevi
2012/07/31 23:03:48
nit: I'm mixed on specifically referencing crypto/
Mehrdad
2012/07/31 23:36:33
I feel that not saying this function is cryptograp
Ryan Sleevi
2012/08/01 17:08:55
My view of the motivation of crypto::RandBytes() i
Mehrdad
2012/08/01 17:19:03
No, I agree, RandBytes should definitely be in cry
| |
37 BASE_EXPORT void RandBytes(void* output, size_t output_length); | 38 BASE_EXPORT void RandBytes(void* output, size_t output_length); |
38 | 39 |
39 // Fills a string of length |length| with with cryptographically strong random | 40 // Fills a string of length |length| with with random data and returns it. |
40 // data and returns it. |length| should be nonzero. | 41 // |length| should be nonzero. |
42 // | |
43 // Note: The random data is cryptographically secure, but use the RNG in crypto/ | |
44 // for security-sensitive purposes instead of this function. | |
41 // | 45 // |
42 // Note that this is a variation of |RandBytes| with a different return type. | 46 // Note that this is a variation of |RandBytes| with a different return type. |
43 BASE_EXPORT std::string RandBytesAsString(size_t length); | 47 BASE_EXPORT std::string RandBytesAsString(size_t length); |
44 | 48 |
45 #ifdef OS_POSIX | 49 #ifdef OS_POSIX |
46 BASE_EXPORT int GetUrandomFD(); | 50 BASE_EXPORT int GetUrandomFD(); |
47 #endif | 51 #endif |
48 | 52 |
49 } // namespace base | 53 } // namespace base |
50 | 54 |
51 #endif // BASE_RAND_UTIL_H_ | 55 #endif // BASE_RAND_UTIL_H_ |
OLD | NEW |