OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 std::string CreateRandomString(size_t length); | 29 std::string CreateRandomString(size_t length); |
30 | 30 |
31 // Generates a (cryptographically) random string of the given length. | 31 // Generates a (cryptographically) random string of the given length. |
32 // We generate base64 values so that they will be printable. | 32 // We generate base64 values so that they will be printable. |
33 // Return false if the random number generator failed. | 33 // Return false if the random number generator failed. |
34 bool CreateRandomString(size_t length, std::string* str); | 34 bool CreateRandomString(size_t length, std::string* str); |
35 | 35 |
36 // Generates a (cryptographically) random string of the given length, | 36 // Generates a (cryptographically) random string of the given length, |
37 // with characters from the given table. Return false if the random | 37 // with characters from the given table. Return false if the random |
38 // number generator failed. | 38 // number generator failed. |
| 39 // For ease of implementation, the function requires that the table |
| 40 // size evenly divide 256; otherwise, it returns false. |
39 bool CreateRandomString(size_t length, const std::string& table, | 41 bool CreateRandomString(size_t length, const std::string& table, |
40 std::string* str); | 42 std::string* str); |
41 | 43 |
42 // Generates (cryptographically) random data of the given length. | 44 // Generates (cryptographically) random data of the given length. |
43 // Return false if the random number generator failed. | 45 // Return false if the random number generator failed. |
44 bool CreateRandomData(size_t length, std::string* data); | 46 bool CreateRandomData(size_t length, std::string* data); |
45 | 47 |
46 // Generates a (cryptographically) random UUID version 4 string. | 48 // Generates a (cryptographically) random UUID version 4 string. |
47 std::string CreateRandomUuid(); | 49 std::string CreateRandomUuid(); |
48 | 50 |
49 // Generates a random id. | 51 // Generates a random id. |
50 uint32_t CreateRandomId(); | 52 uint32_t CreateRandomId(); |
51 | 53 |
52 // Generates a 64 bit random id. | 54 // Generates a 64 bit random id. |
53 uint64_t CreateRandomId64(); | 55 uint64_t CreateRandomId64(); |
54 | 56 |
55 // Generates a random id > 0. | 57 // Generates a random id > 0. |
56 uint32_t CreateRandomNonZeroId(); | 58 uint32_t CreateRandomNonZeroId(); |
57 | 59 |
58 // Generates a random double between 0.0 (inclusive) and 1.0 (exclusive). | 60 // Generates a random double between 0.0 (inclusive) and 1.0 (exclusive). |
59 double CreateRandomDouble(); | 61 double CreateRandomDouble(); |
60 | 62 |
61 } // namespace rtc | 63 } // namespace rtc |
62 | 64 |
63 #endif // WEBRTC_BASE_HELPERS_H_ | 65 #endif // WEBRTC_BASE_HELPERS_H_ |
OLD | NEW |